T-SQL中找出一個表的全部外鍵關聯表
二種方法(下例中表名爲T_Work)sql
1.SQL查詢系統表 spa
- SELECT 主鍵列ID=b.rkey
- ,主鍵列名=(SELECT name FROM syscolumns WHERE colid=b.rkey AND id=b.rkeyid)
- ,外鍵表ID=b.fkeyid
- ,外鍵表名稱=object_name(b.fkeyid)
- ,外鍵列ID=b.fkey
- ,外鍵列名=(SELECT name FROM syscolumns WHERE colid=b.fkey AND id=b.fkeyid)
- ,級聯更新=ObjectProperty(a.id,'CnstIsUpdateCascade')
- ,級聯刪除=ObjectProperty(a.id,'CnstIsDeleteCascade')
- FROM sysobjects a
- join sysforeignkeys b on a.id=b.constid
- join sysobjects c on a.parent_obj=c.id
- where a.xtype='f' AND c.xtype='U'
- and object_name(b.rkeyid)='T_Work'
2.系統存儲過程string
- exec sp_helpconstraint T_Work
歡迎關注本站公眾號,獲取更多信息