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

Posted on 2006-10-24
Last Modified: 2008-01-09

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

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.

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

Question by:Richard Quadling
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 10

Expert Comment

ID: 17795526
the second row will not be added
LVL 40

Author Comment

by:Richard Quadling
ID: 17795538
How do I prove that? Is there an index dump facility?
LVL 10

Accepted Solution

AaronAbend earned 150 total points
ID: 17795612
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)

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 40

Author Comment

by:Richard Quadling
ID: 17796108
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).
LVL 10

Assisted Solution

AaronAbend earned 150 total points
ID: 17796532
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.

LVL 40

Author Comment

by:Richard Quadling
ID: 17801535
That's great. Confirming some of the bits of knowledge I had.


Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

628 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