Skip to content

Instantly share code, notes, and snippets.

@richardkundl
Created February 21, 2015 14:14
Show Gist options
  • Save richardkundl/c3de8f33985c07cb8e4a to your computer and use it in GitHub Desktop.
Save richardkundl/c3de8f33985c07cb8e4a to your computer and use it in GitHub Desktop.
Find table and col from foreign key name
SELECT
OBJECT_NAME(f.parent_object_id) TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName
FROM
sys.foreign_keys AS f
INNER JOIN
sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN
sys.tables t
ON t.OBJECT_ID = fc.referenced_object_id
WHERE
f.name = 'FK2EDAA40B5608C6EC' -- foreign key name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment