0

在执行以下查询后,我试图确保当我对数据库进行 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 
4

1 回答 1

0

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

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

于 2013-10-17T14:33:36.207 回答