Technical Article

Script to get Foreign key details

,

Script to get Foreign key details

select  
object_name(parent_object_id) as Table_name,
c.name,
object_name(constraint_object_id)as FK_Name,
constraint_column_id,
object_name(referenced_object_id)as Referred_Table,
r.name as referred_column_name
 from sys.foreign_key_columns  f
 left join 
sys.columns c on f.parent_object_id=c.object_id 
and f.parent_column_id=c.column_id 
left join
sys.columns r on f.referenced_object_id=r.object_id 
and f.referenced_column_id = r.column_id 
order by table_name

Rate

1 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

1 (1)

You rated this post out of 5. Change rating