gpt4 book ai didi

MySql 检查外键约束是否存在

转载 作者:行者123 更新时间:2023-11-29 04:19:31 25 4
gpt4 key购买 nike

如果我有:

create table order_items
(
orderid int unsigned not null references orders(orderid),
isbn char(13) not null,
quantity tinyint unsigned,

primary key (orderid, isbn)

);

如何检查 orderid int unsigned not null references orders(orderid) 外键是否存在?

最佳答案

您可以像这样使用 INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS:

SELECT *
FROM information_schema.REFERENTIAL_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = '<schema>'
AND REFERENCED_TABLE_NAME = 'order_items'
AND CONSTRAINT_NAME = 'orderid'

关于MySql 检查外键约束是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29185417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com