How to remove a unique index referenced by foreign keys?

I have a table, name it Users. This table has a primary key called Id. Despite the presence Idof a primary key (unique clustered), it has a different index (unique non-clustered) in the same column ( Id).

I would like to remove this restriction, but foreign keys reference this unique non-clustered index and I get an error The constraint ... is being referenced by table....

What is the best way to drop such an index? Do you have any scripts that drop, do something, and recreate a foreign key in a specific column in a particular table? There are many foreign keys, so it would be nice if I could do this automatically. I could use INFORMATION_SCHEMA and another system object to retrieve information about these keys, but I do not want to write what has already been written or can be done in another way.

+3
source share
2 answers

To discard the nonclustered index referenced by the foreign key, you must remove the foreign key constraint.

, SQL Server Central. "" , , .

+2

:

  • , , , , .
  • ,

, . script, .

+1

Source: https://habr.com/ru/post/1726530/


All Articles