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.
Author |
Topic |
oracle765
Starting Member
13 Posts |
Posted - 2013-03-06 : 19:17:52
|
I am trying to insert records into the database as followsinsert into lookuptableselect * from lookuptable1which producesMsg 2627, Level 14, State 1, Line 1Violation of UNIQUE KEY constraint 'uqLookuptable1cols1'. Cannot insert duplicate key in object 'dbo.lookuptable'.The statement has been terminated.Is there a way to handle this error so I can carry on inserting the rest of the records into the tableA Lynch |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-03-06 : 19:50:19
|
See script below - replace the "uniqueColumn" with the column that is referenced in the constraint.insert into lookuptableselect * from lookuptable1 aWHERE NOT EXISTS (SELECT * FROM lookuptable b WHERE b.uniqueColumn = a.uniqueColumn) |
|
|
|
|
|