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
 do not allow duplicate

Author  Topic 

Madhavi.extarc
Starting Member

7 Posts

Posted - 2014-04-17 : 08:31:04
Hi,

Is that possible to restrict inserting the record if record already exist in the table.

Scenario: query should be

we are inserting a bulk information of data, it should not insert the row if it already exist in the table. excluding that it should insert the other rows


Madhavi

Robowski
Posting Yak Master

101 Posts

Posted - 2014-04-17 : 09:05:47
quote:
Originally posted by Madhavi.extarc

Hi,

Is that possible to restrict inserting the record if record already exist in the table.

Scenario: query should be

we are inserting a bulk information of data, it should not insert the row if it already exist in the table. excluding that it should insert the other rows


Madhavi



yes, create a unique constraint on the columns you want to be unique

http://technet.microsoft.com/en-us/library/ms190024.aspx

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-04-17 : 12:12:21
How are you bulk inserting your rows? Are you using BCP or other tool?

As Robowski suggested, you should use a unique constraint. However, if you want to be able to "bulk insert" all the rows except the duplicates you may need to do some other work. Something like using SSIS and do a lookup. Another alternative, that may work for you is to use the IGNORE_DUP_KEY option on the constraint. That will ignore rows that violate the constraint, but allow the other rows to continue to be inserted.
Go to Top of Page
   

- Advertisement -