drop index does not work for unique keys

what is the reason DROP index syntax is disabled for deleting unique keys (non PKs)

thanks
LVL 6
anushahannaAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if you have a PK and a UK, you will also have 2 indexes, 1 index per UK or PK constraint.
for the rest, it's the same situation: the database engine will not allow to drop the index.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this is because the PK is relying on the underlying index for it's function.

imagine you had a 2GB table with a primary key, but no index on that column.
the primary key constraint would have to do a full table scan for each insert & update for that field value !!!
0
 
CluskittCommented:
If you want to drop the index (possibly for rebuilding it), then drop the constraint first.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
anushahannaAuthor Commented:
>>this is because the PK is relying on the underlying index for it's function.

even if PK and UK are both different? (example PK is on Col1 and UK is on Col3..)
0
 
anushahannaAuthor Commented:
are you saying PK will be relying on the unique index, regardless if they are the same or 2 diff indexes?
0
 
anushahannaAuthor Commented:
will DROP INDEX syntax work sometimes and othertimes not, for UNIQUE Indexes?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>are you saying PK will be relying on the unique index, regardless if they are the same or 2 diff indexes?

no. let me clarify:
when you create a PK, sql server will create automatically create a index, for that PK constraint. and it will not let you drop that index.

when you create a UC (unique constraint), sql server will create automatically create a index, for that UC constraint. and it will not let you drop that index.

when you create whatever index, they will NOT be used for any PK or UC, and sql will let your drop that index without issues
this includes also unique indexes, as they are not created by a constraint as such

0
 
anushahannaAuthor Commented:
thanks angelIII, for the helpful explanation.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.