How do I change the order of my table fields without deleting the field and re-inserting it, using PHP myAdmin?
9 Answers
ALTER TABLE `table_name` MODIFY `column_you_want_to_move` DATATYPE AFTER `column`
DATATYPE is something like DATETIME or VARCHAR(20) ..etc

- 7,470
- 3
- 38
- 54
-
For me, it must be: etc MODIFY COLUMN `column_you_want_etc` – cssyphus Nov 24 '13 at 03:08
If you have phpMyAdmin 4.0.0+, you can use the phpMyAdmin Feature under Structure:

- 930
- 8
- 16
-
1It is only work since version 4.0, phpMyAdmin. I checked phpMyAdmin Version 3.5.1 and there was no such function. – Yevgeniy Afanasyev Sep 14 '15 at 00:12
Something like this will help
ALTER TABLE Person MODIFY COLUMN last_name VARCHAR(50) AFTER first_name;
This will move last_name
right after first_name
in order.

- 241
- 3
- 2
-
What if you want to make the column the first column? Ie, so it's not AFTER anything. I tried `"... BEFORE current_first_col"` but it doesn't recognise BEFORE. – Max Williams Apr 17 '13 at 09:43
-
3Aha, just answered my own comment - the syntax is `ALTER TABLE Person MODIFY COLUMN last_name VARCHAR(50) FIRST;` to make it the first column. – Max Williams Apr 17 '13 at 09:44
Since version 4.0, phpMyAdmin has a "Move columns" dialog in Structure, that permits you to graphically move columns in the structure.

- 8,879
- 3
- 29
- 29
-
It isn't actually moving the columns. Go to other browser and see that the columns order are the same after teh change. – machineaddict Sep 12 '13 at 10:38
-
1
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;

- 265,109
- 74
- 539
- 565
It's simple. Just go to PHPmyadmin, click on your database, then click table. Then click on structure. Below the table look for the button, "Move columns". Click and order the columns the way you want.

- 61
- 7
Another alternative:
CREATE new_table SELECT columns-in-new-order FROM old_table;

- 15,750
- 31
- 68
- 83

- 11
- 1
if you have MySQL Workbench you can easily reorder columns using mouse, graphically.
Just connect to your database, select your table and after right click, alter table and then drag columns to reorder them.

- 9,379
- 1
- 25
- 51

- 799
- 1
- 8
- 18