0

I have the data I need to create new records in a table.

However, at least some of the records I'll be inserting already exist (possibly all).

What is the proper statement to avoid duplicate records?

Russell Alan
  • 116
  • 10
  • What if you tried? Would you learn from the docs if you read about the SELECT and Predicates on Join? – clifton_h Aug 16 '17 at 13:37
  • Look into `WHERE NOT EXISTS`... – Dave C Aug 16 '17 at 13:38
  • The proper statement is MERGE https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql – David Browne - Microsoft Aug 16 '17 at 13:39
  • I'm not sure I would have closed this as duplicate. Another option for you to consider would be to add a unique constraint on the columns which define a pair of records as being "duplicate." With such a constraint in place, any attempt to insert a duplicate would fail at the database level. – Tim Biegeleisen Aug 16 '17 at 13:40
  • Thanks for the suggestions. "Where Not Exists" should take care of it and sorry for the duplicate – Russell Alan Aug 16 '17 at 13:54

0 Answers0