Thursday, 23 September 2010

MySQL: Changing the order of a table column

In an ideal purely standard SQL world, one should never have to care about the order of a table's columns. But we're not in an ideal world, and sometime we want to change the position of a table column. Here's how to do it:

ALTER TABLE mytable MODIFY column_move <WHATEVER TYPE IT IS>  AFTER another_column

Note that you need to MODIFY the column with its exact type not to loose any data. Copy/Pasting is your friend here. You can also use BEFORE instead of after.

No comments:

Post a Comment