For SQL 2005+
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[sourcecode language="sql"] DECLARE @tableName nvarchar(MAX) SET @tableName = 'tableName' -- (1) SELECT DISTINCT ccu.table_name, ccu.constraint_name FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc ON rc.unique_constraint_name = tc.constraint_name INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON ccu.constraint_name = rc.constraint_name WHERE tc.table_name = @tableName [/sourcecode] |
Notes:
- Change line (1) to specify the table name.