Re: BULK INSERT ignores UNIQUE index with IGNORE_DUP_KEY set?
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Sat, 23 Jun 2007 09:09:35 +0000 (UTC)
Weyus (weyus@xxxxxxx) writes:
Q1) Will a regular INSERT that attempts to insert duplicate data getHowever, my question Q1 still stands - what is the behavior of an
an error back or just a warning?
...
INSERT of duplicate data against this type of index - I suspect that
you get a warning and not an error - is that correct?
Yes, SQL Server only emits a warning. However, there is a catch, some
client APIs incorrectly interprets this as an error. If run:
CREATE TABLE blamblam (a int NOT NULL)
CREATE UNIQUE INDEX updix ON blamblam(a) WITH IGNORE_DUP_KEY
go
EXEC master..xp_cmdshell 'ECHO 12 > C:\temp\blamblam.txt'
EXEC master..xp_cmdshell 'ECHO 12 >> C:\temp\blamblam.txt'
go
BULK INSERT blamblam FROM 'C:\temp\blamblam.txt'
go
SELECT * FROM blamblam
go
DROP TABLE blamblam
I get this output from Mgmt Studio:
Duplicate key was ignored.
(1 row(s) affected)
a
-----------
12
(1 row(s) affected)
But from Query Analyzer, against the same server instance, I get:
Server: Msg 3604, Level 16, State 1, Line 1
Duplicate key was ignored.
a
-----------
12
(1 row(s) affected)
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.
- References:
- Prev by Date: Re: correct syntax for this select in SQL Server?
- Next by Date: Re: Deadlock transaction
- Previous by thread: Re: BULK INSERT ignores UNIQUE index with IGNORE_DUP_KEY set?
- Index(es):
Relevant Pages
|
Loading