带外键Mysql
Posted 猴子哥669
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带外键Mysql相关的知识,希望对你有一定的参考价值。
带外键的表格的查询
复制代码
//////////////////查询指定表外键约束
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)=‘要查询的表名‘;
以上是关于带外键Mysql的主要内容,如果未能解决你的问题,请参考以下文章
mysql执行带外键的sql文件时出现mysql ERROR 1215 (HY000): Cannot add foreign key constraint的解决
我有两个带外键的表,我想在第一个表中按下外键,第二个表出现数据
删除带外键的表foreign key constraint fails报错