微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sqlserver获取表外键的SQL语句

select t1.name as clmnName,t2.rtableName as fkTbl,t2.name as fkClmn from (select col.name,f.constid as temp  from syscolumns col,sysforeignkeys f  where f.fkeyid=col.id  and f.fkey=col.colid  and f.constid in  ( select distinct(id)     from sysobjects    where OBJECT_NAME(parent_obj)='表名'    and xtype='F'   )  ) as t1,(select OBJECT_NAME(f.rkeyid) as rtableName,col.name,sysforeignkeys f  where f.rkeyid=col.id  and f.rkey=col.colid  and f.constid in  ( select distinct(id)    from sysobjects    where OBJECT_NAME(parent_obj)='表名'    and xtype='F'  ) ) as t2 where t1.temp=t2.temp

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐