November 2, 2005 at 6:49 am
Hi,
Perhaps someone has already written this script.
Based on a table name, I would like to identify details of the foreign keys (Table name, column names) that reference the table.
Thanks.
Regards,
PK.
November 2, 2005 at 7:21 am
SELECT (CASE WHEN OBJECTPROPERTY(CONSTID, 'CNSTISDISABLED') = 0 THEN 'ENABLED' ELSE 'DISABLED' END) AS STATUS,
OBJECT_NAME(CONSTID) AS CONSTRAINT_NAME,
OBJECT_NAME(FKEYID) AS TABLE_NAME,
COL_NAME(FKEYID, FKEY) AS COLUMN_NAME,
OBJECT_NAME(RKEYID) AS REFERENCED_TABLE_NAME,
COL_NAME(RKEYID, RKEY) AS REFERENCED_COLUMN_NAME
FROM SYSFOREIGNKEYS
WHERE OBJECT_NAME(RKEYID) = 'your table name here'
ORDER BY TABLE_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_NAME, KEYNO
GO
November 2, 2005 at 9:31 am
Thanks rsharma. Your help is much appreciated.
Regards,
PK.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply