As a DBA or even as a SQL Server Programmer, we may need a quick script to find relationship between tables. Here is the script which helped me a lot, hope this will be useful for you too
1: SELECT OBJECT_NAME(rkeyid) ParentTable2: ,OBJECT_NAME(fkeyid) ChildTable3: ,OBJECT_NAME(constid) FKey4: ,c1.name FKey_Col5: ,c2.name Ref_KeyCol6: FROM sys.sysforeignkeys s7: INNER JOIN sys.syscolumns c1 ON ( s.fkeyid = c1.id8: AND s.fkey = c1.colid9: )10: INNER JOIN syscolumns c2 ON ( s.rkeyid = c2.id11: AND s.rkey = c2.colid12: )13: ORDER BY 1,2
Post a Comment
Post a Comment