Entry
How can I change the order of columns in a MySQL table?
How can I move a table field to a new position?
May 10th, 2000 20:05
Nathan Wallace, indrek siitan
um, what's the actual need for this besides just a nice look in the
mysql client? you never should rely on the order of "select * from
table" anyway.
but, if there's a will, there's a way:
CREATE TABLE blaah (
col1 int,
col3 int,
col2 int
);
now, let's put them in order:
ALTER TABLE blaah ADD tempcol int AFTER col1;
UPDATE blaah SET tempcol=col2;
ALTER TABLE blaah DROP col2;
ALTER TABLE blaah CHANGE tempcol col2 int;