SQL Command to Change Column Order in a MySQL Table

By | February 4, 2014

Sometimes you need to change column order in a table. If you don’t have access to latest phpmyadmin version (4.0 and above), you don’t have any graphic solution to do this and you’ll have to use an SQL query.

First of all, you need to identify the type of field you want to move. It should look like VARCHAR(25), or INT(11) or something like this.

You can see some types in the image below
hotel

When you know what to move, let’s build the query. We’ll move hotel_bookingid column to the second place, just after id.

ALTER TABLE `hotels` MODIFY COLUMN `hotel_bookingid` INT(11) AFTER `id`

Please, note, that you need to include field type after its name. So if you want to move our_rating column, the query will look like:

ALTER TABLE `hotels` MODIFY COLUMN `our_rating` FLOAT AFTER `id`

Hope this will help someone, who doesn’t like the most recent version of PHPMyadmin or just doesn’t have access to it.

Leave a Reply