2013-10-13 28 views
0

我試圖確保何時mysqldump數據庫的約束是按照數字順序執行下面的查詢後。當我做一個沒有AFTER的轉儲(不起作用)時,它顯示phppos_sales_ibfk_3作爲第一個約束。mysql添加約束(ALTER)如何將它們按順序

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 
+0

*爲什麼*約束的定義順序對您來說很重要? – eggyal

+0

這只是在我導出數據庫時保持組織有序。我知道這並不重要(如果有的話),但我很好奇 –

+0

我懷疑你將不得不吞下你的強迫症在這一個:) – eggyal

回答

0

的 「ALTER TABLE」 中的 「添加約束」 部分不允許關鍵字「AFTER」。

您可以控制列在表格中的顯示位置,但無法控制顯示約束的位置。