Solved

drop index does not work for unique keys

Posted on 2010-08-19
8
275 Views
Last Modified: 2012-05-10
what is the reason DROP index syntax is disabled for deleting unique keys (non PKs)

thanks
0
Comment
Question by:anushahanna
  • 4
  • 3
8 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 425 total points
ID: 33474819
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
 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 75 total points
ID: 33474894
If you want to drop the index (possibly for rebuilding it), then drop the constraint first.
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33475442
>>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
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 425 total points
ID: 33475652
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 6

Author Comment

by:anushahanna
ID: 33476646
are you saying PK will be relying on the unique index, regardless if they are the same or 2 diff indexes?
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33476973
will DROP INDEX syntax work sometimes and othertimes not, for UNIQUE Indexes?
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 425 total points
ID: 33479687
>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
 
LVL 6

Author Comment

by:anushahanna
ID: 33484609
thanks angelIII, for the helpful explanation.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

707 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

17 Experts available now in Live!

Get 1:1 Help Now