select
f.constraint_object_id, o.name as constraint_object,
f.constraint_column_id, --object_name(f.constraint_column_id) as constraint_column,
f.parent_object_id, object_name(f.parent_object_id) as parent_object,
f.parent_column_id, object_name(f.parent_column_id) as parent_column,
f.referenced_object_id, object_name(f.referenced_object_id) as referenced_object,
f.referenced_column_id --, object_name(f.referenced_column_id) as referenced_column
from sys.foreign_key_columns f
-- filter by schema:
inner join sys.objects o on o.object_id = f.constraint_object_id and SCHEMA_NAME(o.schema_id) = 'dbo'
Another good script:
No comments:
Post a Comment