Unable to drop UNIQUE constraint

sql, sql-server, sql-server-2005, sql-server-2008

Solution

Your Query will return the Index name you will need to Drop the index created for the Unique Constraint

use this query

DROP INDEX Index_Name
ON Schema.Table_Name

A unique Constraint creates a `Unique Non-Clustered Index` behind the scenes to enforce the uniqueness on that column.

Also if you need to create this INDEX again after insert you can simply disable it and once you have done whatever you wanted to do, you can enable it afterwards.

something like this...

ALTER INDEX [Index_Name] ON Schema.Table_Name DISABLE
GO

/* Do your Stuff here  */

ALTER INDEX [Index_Name] ON Schema.Table_Name REBUILD
GO

Problem

I wanted to drop some constraints on a table. So, first I have to find out names of the constraints and then see which ones I want to drop. For the first task, I used the query - ``` SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID('YourTableName') ``` I noted the name of a unique constraint on my table from the name column returned by this query. One of the constraint names is UNIQ_YourTableName_01. To drop that constraint, I used - ``` ALTER TABLE YourTableName DROP CONSTRAINT UNIQ_YourTableName_01 ``` I get an error - UNIQ_YourTableName_01 is not a constraint. Could not drop constraint. See previous errors. How do I fix this ? Thanks.

Original source