select
f.constraint_object_id, object_name(f.constraint_ object_id) as constraint_object,
f.constraint_column_id, --object_name(f.constraint_ column_id) as constraint_column, --FK name
f.parent_object_id, object_name(f.parent_object_ id) as parent_object, --FK table
f.parent_column_id, object_name(f.parent_column_ id) as parent_column, --FK column
f.referenced_object_id, object_name(f.referenced_ object_id) as referenced_object, --PK table
f.referenced_column_id --, object_name(f.referenced_ column_id) as referenced_column --PK column
from sys.foreign_key_columns f
inner join sys.objects o on o.object_id = f.constraint_object_id
and SCHEMA_NAME(o.schema_id) <> 'dbo' -- filter by scema of the constraint
where object_name(referenced_object_ id) like '%XXX%' --filter by table name
No comments:
Post a Comment