Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
sms_error_-_key_violation [2019/01/27 11:30] 127.0.0.1 external edit |
sms_error_-_key_violation [2019/07/18 12:53] (current) orichards [Open Database Browser] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | + | ||
| Each record in the SMS datbase (and most others) has a //key// field. This field uniquely identifies the record (row of data) and is used by the database to quickly find the record. In SMS tables, the first column in the table (usually ending in " | Each record in the SMS datbase (and most others) has a //key// field. This field uniquely identifies the record (row of data) and is used by the database to quickly find the record. In SMS tables, the first column in the table (usually ending in " | ||
| - | |||
| - | |||
| A "Key Violation" | A "Key Violation" | ||
| - | |||
| - | |||
| ===== Steps ===== | ===== Steps ===== | ||
| **Make sure all users are out of SMS while the following is being done.** | **Make sure all users are out of SMS while the following is being done.** | ||
| + | ==== Open Database Browser ==== | ||
| - | + | | |
| - | + | - Run the [[:dbrebuild|DBRebuild]]. | |
| - | ==== Open Database Browser ==== | + | - Run the [[:id_repair|IDRepair]] utility (unless customer has a flag stating otherwise) |
| - | | + | |
| - | - Run the [[dbrebuild]]. | + | |
| - | - Run the [[id_repair]] utility (unless customer has a flag stating otherwise) | + | |
| - Open the DBBrowser. | - Open the DBBrowser. | ||
| + | ==== Look for Bad Data At the Top of Each Table ==== | ||
| - | ==== Look for Bad Data At the Top of Each Table ==== | ||
| - Delete any blank records at the top of the database (no entries in ANY field in a given row). | - Delete any blank records at the top of the database (no entries in ANY field in a given row). | ||
| - Records with blank key fields. If the data looks meaningful, consult technical support before deleting this record. | - Records with blank key fields. If the data looks meaningful, consult technical support before deleting this record. | ||
| - | | + | |
| - Delete any large negative values records at the top of the database (i.e. -117346859). | - Delete any large negative values records at the top of the database (i.e. -117346859). | ||
| - | - Renumber any normal size negative number with the psotive | + | - Renumber any normal size negative number with the positive |
| - | * If you get a key violation renumbering it (meaning the positive record already exists), delete the negative record. | + | * If you get a key violation renumbering it (meaning the positive record already exists), delete the negative record. |
| - | + | ||
| ==== Query the Tables for Problems ==== | ==== Query the Tables for Problems ==== | ||
| + | < | ||
| + | < | ||
| - | < | + | < |
| - | |||
| - | |||
| - | < | ||
| - | |||
| - | |||
| - | |||
| - | < | ||
| - Run these all queries for the following tables and associated IDs as appropriate: | - Run these all queries for the following tables and associated IDs as appropriate: | ||
| - | | + | |
| - | * Contact Database - ContactID | + | * Contact Database - ContactID |
| - | * Customer Database - CustomerID | + | * Customer Database - CustomerID |
| - | * Estimate Database - OrderID | + | * Estimate Database - OrderID |
| - | * Order Database - OrderID | + | * Order Database - OrderID |
| - | * Order Details Database - OrderDetailID | + | * Order Details Database - OrderDetailID |
| - | * Estimate Details Database - OrderDetailID | + | * Estimate Details Database - OrderDetailID |
| - | * Estimate Modifiers Database - ID | + | * Estimate Modifiers Database - ID |
| - | * Order Modifiers Database - ID | + | * Order Modifiers Database - ID |
| - | * Deleted Records Database - ID (SMS > 8.9) | + | * Deleted Records Database - ID (SMS > 8.9) |
| - | * GL Database - ID | + | * GL Database - ID |
| - | * Payments Database - PaymentID | + | * Payments Database - PaymentID |
| - | * Product Database - ProductID | + | * Product Database - ProductID |
| - | * Deleted Records (only in 8.9) | + | * Deleted Records (only in 8.9) |
| - | - Run **SQL 1** to locate conflicting ID Numbers. | + | - Run **SQL 1** to locate conflicting ID Numbers. |
| - | - Each record in a database must have a unique and distinct primary key ID number (i.e. Contact Database uses " | + | - Each record in a database must have a unique and distinct primary key ID number (i.e. Contact Database uses " |
| - | - If an entry is posted, such as updating a contact record using ContactID # 5642 and one already exists for a different contact, then this will result in an immediate key violation. The ID number must be changed to one that is unused. | + | - If an entry is posted, such as updating a contact record using ContactID # 5642 and one already exists for a different contact, then this will result in an immediate key violation. The ID number must be changed to one that is unused. |
| - | - If the information is the same in both records, you will need to delete one of the 2 records. | + | - If the information is the same in both records, you will need to delete one of the 2 records. |
| - | - In some cases, the primary key is made up of two fields like the GL (i.e. the ID and the StoreID make up the primary key.) | + | - In some cases, the primary key is made up of two fields like the GL (i.e. the ID and the StoreID make up the primary key.) |
| - | - If you have an ID that is the same, but the information is different in this case, you will need to assign a new ID | + | - If you have an ID that is the same, but the information is different in this case, you will need to assign a new ID |
| - | - If you have duplicate ContactIDs in the Contact table, use **SQL 2** to correct all the appropriate tables: | + | - If you have duplicate ContactIDs in the Contact table, use **SQL 2** to correct all the appropriate tables: |
| - | - **SQL 3** (far below) can be used to fix duplicate keys in other tables. | + | - **SQL 3** (far below) can be used to fix duplicate keys in other tables. |
| - | + | ||
| - | + | ||
| ===== SQL 1 ===== | ===== SQL 1 ===== | ||
| - | |||
| - | |||
| <code sql> | <code sql> | ||
| - | SELECT ContactID, | + | SELECT ContactID, |
| FROM " | FROM " | ||
| GROUP BY ContactID | GROUP BY ContactID | ||
| ORDER BY CustCNT DESC | ORDER BY CustCNT DESC | ||
| </ | </ | ||
| - | * Note that any word can be substituted for " | ||
| - | * Example : | ||
| - | |||
| + | * Note that any word can be substituted for " | ||
| + | * Example : | ||
| <code sql> | <code sql> | ||
| - | SELECT | + | SELECT |
| FROM "Order Database" | FROM "Order Database" | ||
| GROUP BY OrderID | GROUP BY OrderID | ||
| - | HAVING | + | HAVING |
| - | ORDER BY CustCNT | + | ORDER BY CustCNT |
| </ | </ | ||
| - | |||
| - | |||
| ===== SQL 2 ===== | ===== SQL 2 ===== | ||
| - | |||
| - | |||
| <code sql> | <code sql> | ||
| - | // Get a list of all duplicated contacts | + | // GET a list OF ALL duplicated contacts |
| - | Select | + | SELECT |
| - | From " | + | FROM " |
| - | Group by ContactID | + | GROUP BY ContactID |
| - | HAVING | + | HAVING |
| ; DupContactList | ; DupContactList | ||
| - | Create Index TempContactIndex1 | + | CREATE INDEX TempContactIndex1 |
| ; | ; | ||
| - | // Get the Contact, Customer pairing | + | // GET the Contact, Customer pairing |
| - | select | + | SELECT |
| - | from " | + | FROM " |
| - | where ContactID | + | WHERE ContactID |
| ; DupContacts | ; DupContacts | ||
| - | // Make sure you reset the NewContactID | + | // Make sure you reset the NewContactID |
| - | // Update | + | // UPDATE |
| - | update | + | UPDATE |
| - | set NewContactID = OldContactID | + | SET NewContactID = OldContactID |
| - | where CustomerID | + | WHERE CustomerID |
| ; | ; | ||
| - | Create Index TempContactIndex2 | + | CREATE INDEX TempContactIndex2 |
| ; | ; | ||
| - | // Update | + | // UPDATE |
| - | update | + | UPDATE |
| - | set ContactID = (select | + | SET ContactID = (SELECT |
| - | where ContactID | + | WHERE ContactID |
| ; | ; | ||
| - | // Update | + | // UPDATE |
| - | update | + | UPDATE |
| - | set ContactID = (select | + | SET ContactID = (SELECT |
| - | where ContactID | + | WHERE ContactID |
| ; | ; | ||
| - | // Update | + | // UPDATE |
| - | update | + | UPDATE |
| - | set ContactID = (select | + | SET ContactID = (SELECT |
| - | where ContactID | + | WHERE ContactID |
| ; | ; | ||
| - | // Update | + | // UPDATE |
| - | update | + | UPDATE |
| - | set PrimaryContactID = (select | + | SET PrimaryContactID = (SELECT |
| - | where PrimaryContactID | + | WHERE PrimaryContactID |
| ; | ; | ||
| - | // Update | + | // UPDATE |
| - | update | + | UPDATE |
| - | set APContactID = (select | + | SET APContactID = (SELECT |
| - | where APContactID | + | WHERE APContactID |
| ; | ; | ||
| </ | </ | ||
| - | - SQL 3 can be used to fix duplicate keys in the Adjustment, GL, or Payments tables. | ||
| - | |||
| + | - SQL 3 can be used to fix duplicate keys in the Adjustment, GL, or Payments tables. | ||
| ===== SQL 3 ===== | ===== SQL 3 ===== | ||
| - | |||
| - | |||
| <code sql> | <code sql> | ||
| - | Select | + | SELECT |
| - | From "GL Database" | + | FROM "GL Database" |
| - | Group by ID | + | GROUP BY ID |
| - | Order by CNT Desc | + | ORDER BY CNT DESC |
| ;tempa | ;tempa | ||
| - | Select | + | SELECT |
| - | From " | + | FROM " |
| - | where CNT > 1 | + | WHERE CNT > 1 |
| ;tempb | ;tempb | ||
| - | Update | + | UPDATE |
| - | Set ID = ID + 1XXXXXX | + | SET ID = ID + 1XXXXXX |
| - | where ID in (Select | + | WHERE ID IN (SELECT |
| </ | </ | ||
| - | **note:** XXXXXX should represent the number places of the last entry in the table, so ID goes from XXXXXX (6 characters) to 1XXXXXX (1+6 characters). You must then manually resequence the new IDs | + | **note: |
| - | - SQL 4 | + | |
| + | - SQL 4 | ||
| This is only used for a large quantity of duplicate IDs in the GL and Payments tables. It can NOT be used on any other table due to potential key issues. | This is only used for a large quantity of duplicate IDs in the GL and Payments tables. It can NOT be used on any other table due to potential key issues. | ||
| - | |||
| - | |||
| Only use this SQL if you have more than 50 duplicate IDs | Only use this SQL if you have more than 50 duplicate IDs | ||
| - | |||
| - | |||
| ===== SQL 4 ===== | ===== SQL 4 ===== | ||
| - | |||
| - | |||
| <code sql> | <code sql> | ||
| - | Select | + | SELECT |
| - | Count (ID) as CNT, | + | COUNT (ID) AS CNT, |
| - | Min(StoreID) | + | MIN(StoreID) |
| - | Max(StoreID) | + | MAX(StoreID) |
| - | cast(0 as Integer) NewID | + | CAST(0 AS INTEGER) NewID |
| - | From "GL Database" | + | FROM "GL Database" |
| - | Group by ID | + | GROUP BY ID |
| - | having Count(ID) > 1 | + | HAVING COUNT(ID) > 1 |
| - | Order by CNT Desc | + | ORDER BY CNT DESC |
| ;TempA2 | ;TempA2 | ||
| - | create index TempNewIDIndexB | + | CREATE INDEX TempNewIDIndexB |
| ; | ; | ||
| - | update | + | UPDATE |
| - | set NewID = 1 | + | SET NewID = 1 |
| - | + (select Max(ID) from "GL Database" | + | + (SELECT MAX(ID) FROM "GL Database" |
| - | + (select Count(*) from TempA2 T2 where T2.OldID < T1.OldID) | + | + (SELECT COUNT(*) FROM TempA2 T2 WHERE T2.OldID < T1.OldID) |
| ; | ; | ||
| - | update | + | UPDATE |
| - | set ID = (select | + | SET ID = (SELECT |
| - | where StoreID = (select | + | WHERE StoreID = (SELECT |
| ; | ; | ||
| - | select | + | SELECT |
| </ | </ | ||
| - | **Note:** You will need to adjust the Table name and ID name | + | **Note: |
| - | + | ||
| - | + | ||
| - | + | ||
| - | See Also | + | |