SQL 2000/2005/2008 - Find a unique constraint name for a column

I have a table with a column that needs to be updated with a data type. However, triggering any change to the script causes errors due to an unnamed unique restriction.

I need to abandon this restriction, but, unfortunately, I do not know this name. I have a script that currently lists all the unique constraints in a table, but I need to figure out how to go this step further and associate the constraint names with columns.

Select *
From sysobjects
Where sysobjects.xtype = 'UQ' AND sysobjects.parent_obj= OBJECT_ID(N'Users')

it returns

UQ__Users__45F365D3
UQ__Users__46E78AOC

I need to know which column theses are tied to in order to remove the correct one. I need to support SQL 2000, 2005 and 2008.

Any suggestions would be appreciated.

Thanks Ben

+3
1

INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE, .

SELECT 
   CONSTRAINT_NAME 
FROM 
   INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE 
WHERE 
   TABLE_NAME = 'TableName' 
   AND COLUMN_NAME = 'ColumnName'

, SQL 2000 .

+9

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


All Articles