58

How do I change the order of my table fields without deleting the field and re-inserting it, using PHP myAdmin?

4

9 回答 9

73
ALTER TABLE `table_name` MODIFY `column_you_want_to_move` DATATYPE AFTER `column`

DATATYPE 类似于 DATETIME 或 VARCHAR(20) ..etc

于 2011-04-15T05:45:23.290 回答
39

如果您有 phpMyAdmin 4.0.0+,您可以使用结构下的 phpMyAdmin 功能:

于 2014-11-26T13:42:44.087 回答
24

这样的事情会有所帮助

ALTER TABLE Person MODIFY COLUMN last_name VARCHAR(50) AFTER first_name;

这将按顺序last_name移动first_name

于 2012-10-05T08:45:04.873 回答
9

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:

  1. Create a new table with the columns in the new order.

  2. Execute this statement:

    mysql> INSERT INTO new_table -> SELECT columns-in-new-order FROM old_table;

  3. Drop or rename old_table.

  4. Rename the new table to the original name:

    mysql> ALTER TABLE new_table RENAME old_table;

于 2009-12-26T02:10:39.480 回答
8

从 4.0 版开始,phpMyAdmin 在结构中有一个“移动列”对话框,允许您以图形方式移动结构中的列。

于 2013-08-23T19:30:18.613 回答
4
alter table table_name modify column col_name type after col_name
于 2011-10-14T20:41:40.180 回答
2

这很简单。只需转到 PHPmyadmin,单击您的数据库,然后单击表。然后点击结构。在表格下方查找“移动列”按钮。单击并按您想要的方式对列进行排序。

于 2019-02-16T21:57:31.763 回答
1

如果您有MySQL Workbench,您可以使用鼠标轻松地以图形方式重新排序列。

只需连接到您的数据库,选择您的表,然后右键单击,更改表,然后拖动列以重新排序。

于 2015-03-09T07:16:10.657 回答
1

另一种选择:

CREATE new_table SELECT columns-in-new-order FROM old_table;
于 2014-03-20T02:23:33.607 回答