- The table_name placeholder is a placeholder for the table name.
- The I_xxxIDX placeholder is a placeholder for the unique index name.
- The value1 placeholder and the value2 placeholder are placeholders for the duplicate key values.
- The column1 placeholder and the column2 placeholder are the placeholders that represent the column names.
Note Before you follow the instructions in this article, make sure that you have a complete backup copy of the database that you can restore if a problem occurs.
To resolve this problem, either remove the duplicate records from the table to allow for the unique index to be added or determine whether the unique index should be added. To do this, follow these steps:
- On the AOS server, click Start, click Run, type eventvwr.exe, and then click OK.
- In the Event Viewer console tree, click the Application node.
- View the duplicate key error that appears first in the Application log. To do this, double-click the Error and source: Dynamics Server 0x item that appears first in the details pane.
Note The x is a placeholder for the instance of the AOS service that returns the error message.
- Based on the error message that is displayed, replace the table name, the column name, and the index name with the values in the error message in the SQL Server script that you use in the next step.
- After the values are replaced from the actual error, run the following SQL Server script in SQL Query Analyzer or in SQL Server Management Studio.Note Replace the placeholders with the appropriate information when you run the script.
select count(*) as Duplicate_Record_Count, <column1>, <column2> from
<table_name> group by <column1>, <column2> having count(*) > 1
- For each record that is returned in step 5, at least one duplicate record exists. The Duplicate_record_count column indicates how many records are duplicated by using those index values. If duplicate records are found, you must determine whether the records will be removed to add the unique index or whether the unique index should be added. To find all duplicate records, run the following script.Notes
select Distinct a.* from <table_name> a
join (select <column1>, <column2> from <table_name> group by <column1>, <column2> having count(*) > 1) b
on a.<column1> = b.<column1> and a.<column2> = b.<column2>
- Replace the placeholders with the appropriate information before you run the script. You can obtain the information from the error message.
- The Recid column can be used as a key identifier on each table to select or to remove records.
- If you are unsure about how to run the scripts or interpret the results, you can work together with a qualified database administrator (DBA) and a support technician to decide how to process the results.
- Repeat step 5 and step 6 until the script in step 5 returns a null value that indicates that there are no more duplicate values and that the unique index can be added.
- If there is more than one unique index to be added, view the next duplicate key error in the Event Viewer Application log, and then repeat step 4 through step 7 until there are no more duplicate key errors in the Event Viewer Application log.
Article ID: 937765 - Last Review: Jul 14, 2012 - Revision: 1