Last Updated: February 25, 2016
·
795
· arglbr

MySQL: Defining column order

To create [column_name] as the first one on [table_name]:

ALTER TABLE table_name ADD COLUMN column_name INT NULL FIRST;

To create the [columnY] right next [columnX] on [table_name]:

ALTER TABLE table_name ADD COLUMN columnY INT NULL AFTER columnX;

To just change the position of [columnX] (obviously, keeping the data):

ALTER TABLE table_name MODIFY COLUMN columnX INT NULL FIRST;

or

ALTER TABLE table_name MODIFY COLUMN columnX INT NULL AFTER columnX;