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
 New to SQL Server Programming
 Bulk Insert Error

Author  Topic 

ikeguluo
Starting Member

15 Posts

Posted - 2008-10-27 : 07:45:17
Hi

Im trying to do a bulk insert and getting the following error

Msg 2601, Level 14, State 1, Line 1
Cannot insert duplicate key row in object 'dbo.tblStaffDirectory_Area' with unique index 'IX_tblStaffDirectory_Area'.
The statement has been terminated.

Can anyone help with this error

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-27 : 08:05:15
Look for data in your file to see if you've duplicate values appearing in field on which index is defined. If yes, try to remove the duplicate data from file or use IF NOT EXISTS() before insertion to ensure it dont try to insert the duplicate values which causes this error.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-10-27 : 09:14:40
This will(/can) cause a substantial amount of overhead but I tend to bulk load data into a clean staging table with only a clustered identity column first and then load data in to real table using some more "advanced" checks afterwards. But as visakh says a duplicate key is exactly that, you're trying to insert a key more than once that is supposed to be unique.

- Lumbago
Go to Top of Page
   

- Advertisement -