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)='要查詢的表名';

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM