一.查询指定表外键约束
SELECT A.name AS 约束名 ,
OBJECT_NAME(B.parent_object_id) AS 外键表 ,
D.name AS 外键列 ,
OBJECT_NAME(B.referenced_object_id) AS 主健表 ,
C.name AS 主键列
FROM sys.foreign_keys A
INNER JOIN sys.foreign_key_columns B ON A.object_id = B.constraint_object_id
INNER JOIN sys.columns C ON B.parent_object_id = C.object_id
AND B.parent_column_id = C.column_id
INNER JOIN sys.columns D ON B.referenced_object_id = D.object_id
AND B.referenced_column_id = D.column_id
WHERE OBJECT_NAME(B.referenced_object_id) = ‘Position‘;
原文地址:https://www.cnblogs.com/tx720/p/9102012.html
时间: 2024-10-09 17:16:45