Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Data Corruption Issues
 Duplicate Key Row

Author  Topic 

Slive
Starting Member

8 Posts

Posted - 2011-12-22 : 02:35:12
Hi,

I'm getting the following error:

Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert duplicate key row in object 'dbo.tblAccLocDetail' with unique index 'idx1'.(-2147217900)

What I did to try and resolve this was copy the data in this table to excel and then tried grouping it to see if I could spot any strange data (also used filters) as this was how I managed to fix it the last time. Problem is that this takes forever as I do it remotely and searching for it manually is horrible, does anyone know how I can resolve this with a more "productive" solution? Any tools out there that I could try?

Your help will be greatly appreciated.

Thanks,
Rogan.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-22 : 04:14:20
how are you inserting values? is it by passing values directly or from another table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Slive
Starting Member

8 Posts

Posted - 2011-12-22 : 04:50:31
During synchronisation. It inserts from another table, basically from one programs DB to the other.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-12-22 : 07:25:06
First, look at the DDL of the index on the target table to see the columns that are in the unique index idx1.

Then, run the following query on the source table (assuming col1, col2, col3 are the columns in the unique index) to see the duplicate rows.

select
col1,col2,col3
from
SourceTable
group by
col1,col2,col3
having
count(*) > 1
This will tell you the combinations of col1, col2, col3 that are not unique.

At this point, what you want to do depends on your business requirements. For example you may choose to insert only one row from each of the duplicate sets or you may choose to remove the unique constraint on the target table etc.
Go to Top of Page

Sana seofirst
Starting Member

2 Posts

Posted - 2012-02-16 : 02:21:43
Please tell me how find out all employee IDs whose birthday fall today ?
unspammed
Go to Top of Page
   

- Advertisement -