How do I change the order of my table fields without deleting the field and re-inserting it, using PHP myAdmin?
9 回答
ALTER TABLE `table_name` MODIFY `column_you_want_to_move` DATATYPE AFTER `column`
DATATYPE 类似于 DATETIME 或 VARCHAR(20) ..etc
如果您有 phpMyAdmin 4.0.0+,您可以使用结构下的 phpMyAdmin 功能:
这样的事情会有所帮助
ALTER TABLE Person MODIFY COLUMN last_name VARCHAR(50) AFTER first_name;
这将按顺序last_name
移动first_name
。
http://dev.mysql.com/doc/refman/5.0/en/change-column-order.html
From the Aforementioned Source:
If you decide to change the order of table columns anyway, you can do so as follows:
Create a new table with the columns in the new order.
Execute this statement:
mysql>
INSERT INTO new_table -> SELECT columns-in-new-order FROM old_table;
Drop or rename old_table.
Rename the new table to the original name:
mysql>
ALTER TABLE new_table RENAME old_table;
从 4.0 版开始,phpMyAdmin 在结构中有一个“移动列”对话框,允许您以图形方式移动结构中的列。
alter table table_name modify column col_name type after col_name
这很简单。只需转到 PHPmyadmin,单击您的数据库,然后单击表。然后点击结构。在表格下方查找“移动列”按钮。单击并按您想要的方式对列进行排序。
如果您有MySQL Workbench,您可以使用鼠标轻松地以图形方式重新排序列。
只需连接到您的数据库,选择您的表,然后右键单击,更改表,然后拖动列以重新排序。
另一种选择:
CREATE new_table SELECT columns-in-new-order FROM old_table;