Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Difference between
Message
From
28/12/2002 20:04:35
 
 
To
28/12/2002 18:24:49
General information
Forum:
Microsoft SQL Server
Category:
Database design
Miscellaneous
Thread ID:
00736342
Message ID:
00736361
Views:
12
Hmmm...interesting question. According to the BOL:

"If IGNORE_DUP_KEY was specified for the index and an INSERT statement that creates a duplicate key is executed, SQL Server issues a warning and ignores the duplicate row."

It doesn't work in the same manner as VFP. Try the following:
CREATE TABLE mytable (c int identity, d int)
go
create unique nonclustered index nci_mytable_d on mytable(d)
go

insert into mytable values (1)
insert into mytable values (1)
You should see that an ERROR occurs when the second INSERT is executed, causing the statement to be rolled-back. Now continue with this code:
drop index mytable.nci_mytable_d
GO
create unique nonclustered index nci_mytable_d on mytable(d) with IGNORE_DUP_KEY
go
insert into mytable values (1)
this time, you should receive a WARNING about the duplicate key but selecting from the table should display a single row:
select * from mytable
So the only real difference seems to be whether an error or warning is returned by SQL Server.

-Mike

>When creating an index in Enterprise Manager, if you check create unique option, you are offered the option of 'Contraint' or 'Index'. Since 'Index' offers the option to ignore duplicate key it sounds a little like the 'unique' indexes in Fox: the index is unique but the table can hold duplicates; whereas 'contraint' seems to ask for true uniqueness. BOL is not very clear about the difference.
>
>Can someone clarify, please? TIA.
>
>Alex
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform