PHP myAdmin - Change Field Order (Move Up Or Down)

PhpMysqlPhpmyadmin

Php Problem Overview


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

Php Solutions


Solution 1 - Php

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

DATATYPE is something like DATETIME or VARCHAR(20) ..etc

Solution 2 - Php

If you have phpMyAdmin 4.0.0+, you can use the phpMyAdmin Feature under Structure:

http://i.imgur.com/At0PCyB.jpg">

Solution 3 - Php

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.

Solution 4 - Php

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;

  1. Drop or rename old_table.

  2. Rename the new table to the original name:

mysql> ALTER TABLE new_table RENAME old_table;

Solution 5 - Php

Since version 4.0, phpMyAdmin has a "Move columns" dialog in Structure, that permits you to graphically move columns in the structure.

Solution 6 - Php

alter table table_name modify column col_name type after col_name

Solution 7 - Php

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.

Solution 8 - Php

Another alternative:

CREATE new_table SELECT columns-in-new-order FROM old_table;

Solution 9 - Php

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoshuaView Question on Stackoverflow
Solution 1 - PhpPopulusView Answer on Stackoverflow
Solution 2 - PhpTecBeastView Answer on Stackoverflow
Solution 3 - PhpAshishView Answer on Stackoverflow
Solution 4 - PhpSampsonView Answer on Stackoverflow
Solution 5 - PhpMarc DelisleView Answer on Stackoverflow
Solution 6 - PhpCruzView Answer on Stackoverflow
Solution 7 - PhpJoseph AdegbolaView Answer on Stackoverflow
Solution 8 - Phpuser2145716View Answer on Stackoverflow
Solution 9 - PhpPeyman abdollahyView Answer on Stackoverflow