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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to avoid duplicates in bulk insert?

Author  Topic 

shaik.zakeer
Posting Yak Master

117 Posts

Posted - 2008-06-26 : 05:46:32
Hello friends...

i have done some bulk insert from .txt file to database.

in that i have four rows.Initially when i execute the bulk insert it inserted four into the table.

when i runs bulk insert one more time it is inserting same four rows.
but i dont want to allow duplicates.

how can i do?

please help me. is there option in bulk insert to avoid duplicates

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-26 : 06:17:42
Either set a unique constraint on column of table which distinguishes unique records so that it will cause a viloation error on trying to insert duplicates.
Or you can bulkinsert the data onto a temporary table and then compare this with your table and insert only missing records.
Go to Top of Page

shaik.zakeer
Posting Yak Master

117 Posts

Posted - 2008-06-26 : 06:58:40
Thanks for your info.

actually i have created a primary key on id column.first i inserted three rows into the table and then for the second time i have inserted four rows (along with the three old rows+one new row).

But i m unable to get.

Please help me out from this.

Thanks

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-26 : 07:04:54
quote:
Originally posted by shaik.zakeer

Thanks for your info.

actually i have created a primary key on id column.first i inserted three rows into the table and then for the second time i have inserted four rows (along with the three old rows+one new row).

But i m unable to get.

Please help me out from this.

Thanks




if you want bulkinsert to happen even when you provide duplicates. ist better to use the second approach i.e inserrting into temporary table and then inserting into final table after comparison.
Go to Top of Page

shaik.zakeer
Posting Yak Master

117 Posts

Posted - 2008-06-26 : 08:58:28
thanks

Thanks

Go to Top of Page
   

- Advertisement -