Technical Article

Find Parent Child RelationShip

,

Many times with work with unknown databases, most of the time there is not a clear documentation of the relations between tables, however, with this script we are able to find the parent child relations in just a few seconds

select distinct object_name (rkeyid) as parent
,object_name(fkeyid) as child 
from sys.sysforeignkeys
where 
object_name (rkeyid)  in ( select distinct object_name(fkeyid) from sys.sysforeignkeys)

---and object_name (rkeyid) = 'TableName'
--Used this option to filter specific table

Rate

5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (2)

You rated this post out of 5. Change rating