Solved

Confusion about documentation in BOL with regard to "Ignore duplicate key".

Posted on 2006-10-24
6
298 Views
Last Modified: 2008-01-09
Hi.

BOL | Using the SQL Server Tools | User Interface Reference | Visual Database Tools | Properties Page | Database Designer Properties Page | Index/Keys Property Page says ...

[snip]
Create UNIQUE
Select this option to create a unique constraint or index for the selected database table. Specify whether you are creating a constraint or index by selecting either the Constraint or Index button.

Ignore duplicate key   If you create a unique index, you can set this option to ensure each value in an indexed column is unique.
[snip]

What will happen if you 2 rows with the same value for the key column(s)?

0
Comment
Question by:RQuadling
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:AaronAbend
Comment Utility
the second row will not be added
0
 
LVL 40

Author Comment

by:RQuadling
Comment Utility
How do I prove that? Is there an index dump facility?
0
 
LVL 10

Accepted Solution

by:
AaronAbend earned 150 total points
Comment Utility
Insert a dup value - you do not need to see the index - just look at the data in the table...

create table ab(a int )
create unique index adbab on ab(a)   WITH( IGNORE_DUP_KEY = ON)

insert ab select 1
insert ab select 1

... messages:

(1 row(s) affected)

Duplicate key was ignored.
(0 row(s) affected)

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 40

Author Comment

by:RQuadling
Comment Utility
Ah. So the index restricts the insertion of data. What about adding the index to existing data?

(More points as the discussion has wandered a little).
0
 
LVL 10

Assisted Solution

by:AaronAbend
AaronAbend earned 150 total points
Comment Utility
No.. a unique index normally prevents a duplicate value from being entered by issuing an error message. But ignore_dup_key causes that message to go away - but it does not let a duplicate into the table.

If you have an existing table, you can create an index...


create unique index myindexname on mytable(mycol1, mycol2, ...)

and if there are values that duplicate the index build will fail.

In SQL we do not look at indexes directly - they are stored in the database and they are used by the optimizer to speed up queries. You can see which indexes are being used by showing the execution plan in a query analyzer.

A clustered index actually resorts the table itself - so in effect you are looking at the index when you look at data in a table that has a clustered index, but that's not a very important thing to know.

0
 
LVL 40

Author Comment

by:RQuadling
Comment Utility
That's great. Confirming some of the bits of knowledge I had.

Ta!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now