gpt4 book ai didi

mysql添加约束(ALTER)如何将它们按顺序排列

转载 作者:行者123 更新时间:2023-11-30 01:12:40 39 4
gpt4 key购买 nike

我试图确保当我 mysqldump 数据库时约束在执行以下查询后按数字顺序排列。当我在没有 AFTER 的情况下进行转储(这不起作用)时,它显示 phppos_sales_ibfk_3 作为第一个约束。

ALTER TABLE `phppos_sales`
ADD CONSTRAINT `phppos_sales_ibfk_3` FOREIGN KEY (`location_id`) REFERENCES `phppos_locations` (`location_id`);
ADD CONSTRAINT `phppos_sales_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `phppos_employees` (`person_id`),
ADD CONSTRAINT `phppos_sales_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `phppos_customers` (`person_id`),

我试图更改phppos_sales的代码

ALTER TABLE `phppos_sales`
ADD CONSTRAINT `phppos_sales_ibfk_3` AFTER `phppos_sales_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `phppos_locations` (`location_id`);

我收到错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AFTER `phppos_sales_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `phppos_locat' at line 6 

最佳答案

“ALTER TABLE”的“ADD CONSTRAINT”部分不允许使用关键字“AFTER”。

您可以控制列在表中的显示位置,但无法控制约束的显示位置。

关于mysql添加约束(ALTER)如何将它们按顺序排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19347119/

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