I have a table 'users' with 'login' column defined as:
[login] VARCHAR(50) UNIQUE NOT NULL
Now I want to remove this unique constraint/index using SQL script. I found its name UQ_users_7D78A4E7 in my local database but I suppose it has a different name on another database.
What is the best way to drop this unique constraint? Or at least any...
Thanks.
This statement works for me
I have stopped on the script like below (as I have only one non-clustered unique index in this table):
Has anyone comments if this solution is acceptable? Any pros and cons?
Thanks.
I would like to refer a previous question, Because I have faced same problem and solved by this solution. First of all a constraint is always built with a
Hash
value in it's name. So problem is thisHASH
is varies in different Machine or Database. For exampleDF__Companies__IsGlo__6AB17FE4
here6AB17FE4
is the hash value(8 bit). So I am referring a single script which will be fruitful to allIt will drop your default constraint. However if you want to create it again you can simply try this
Finally, just simply run a
DROP
command to drop the column.Expand to database name >> expand to table >> expand to keys >> copy the name of key then execute the below command:
Here UQ__test__3213E83EB607700F is the name of unique key which was created on a particular column on test table.
FOR SQL to drop a constraint
ALTER TABLE [dbo].[tablename] DROP CONSTRAINT [unique key created by sql] GO
alternatively: go to the keys -- right click on unique key and click on drop constraint in new sql editor window. The program writes the code for you.
Hope this helps. Avanish.
This works mostly.