Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IGNORE_DUP_KEY option in SQL Server

I did quite some search in MSDN and Google, but looks like the description for IGNORE_DUP_KEY option is very limited.

My confusions,

  1. Is IGNORE_DUP_KEY option an option for a column? for a table? for a couple of columns? for an index (making index unique)?

  2. If set IGNORE_DUP_KEY to Yes, when insert a batch of records (using bulk insert WriteToServer ADO.Net function) with duplicate keys (for example, I insert some values which already exist in database), SQL Server will not throw an error. The batch job will be completed successfully but the duplicated rows will not be inserted. All other rows will be inserted and SQL Server treat it as a job success. Is my understanding correct?

thanks in advance, George

like image 604
George2 Avatar asked Dec 31 '22 03:12

George2


1 Answers

IGNORE_DUP_KEY is an option of CREATE INDEX and only affects inserts of multiple rows:

IGNORE_DUP_KEY = ON

  • all unique rows get inserted, a warning is issued, and the duplicate rows are not inserted

IGNORE_DUP_KEY = OFF

  • an error is issued and no rows are inserted
like image 169
KM. Avatar answered Jan 11 '23 17:01

KM.