日期:2014-05-17 浏览次数:20638 次
;WITH CTE AS ( SELECT OBJECT_NAME(constraint_object_id) Constraint_Name , OBJECT_NAME(parent_object_id) Table_Name , C.name Column_Name FROM sys.foreign_key_columns FK INNER JOIN sys.columns C ON FK.parent_object_id = C.object_id AND FK.parent_column_id = C.column_id ) SELECT C.Constraint_Name , C.Table_Name , C.Column_Name , OBJECT_NAME(FK.referenced_object_id) Referenced_Table_Name , SC.name Referenced_Column_Name FROM CTE C INNER JOIN sys.foreign_key_columns FK ON C.Constraint_Name = OBJECT_NAME(FK.constraint_object_id) INNER JOIN sys.columns SC ON FK.referenced_object_id = SC.object_id AND FK.referenced_column_id = SC.column_i