Skip to content

Instantly share code, notes, and snippets.

@nikolasd
Last active October 23, 2018 13:37
Show Gist options
  • Save nikolasd/26a5181dd4887d9b8e96671f0f3c78d0 to your computer and use it in GitHub Desktop.
Save nikolasd/26a5181dd4887d9b8e96671f0f3c78d0 to your computer and use it in GitHub Desktop.
Εύρεση ενός FK σε όλα τα Tables
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 COL_NAME(fc.parent_object_id, fc.parent_column_id) = 'HEPRLSID'
ORDER BY OBJECT_NAME(f.parent_object_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment