如何获取SQLSERVER所有表的外键关系参数
答案:2 悬赏:30 手机版
解决时间 2021-12-24 09:41
- 提问者网友:疯子也有疯子的情调
- 2021-12-23 16:12
如何获取SQLSERVER所有表的外键关系参数
最佳答案
- 五星知识达人网友:山君与见山
- 2021-12-23 17:48
---利用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)='指定表名'
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)='指定表名'
全部回答
- 1楼网友:低音帝王
- 2021-12-23 19:01
人生感悟:过生日,送她草莓蛋糕,不要太大,但要足够精致,把你对她的腻称放在蛋糕上。再买一个大的,让她和朋友一起过。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯