sql查詢表的外鍵
發布時間: 2023-06-19 08:40:35
❶ 如何獲取SQLSERVER所有表的外鍵關系參數
---利用Sql查詢指定表的所有外鍵約束及外鍵表名與列名
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)='指定表名'
熱點內容