faqts : Computers : Databases : MySQL : Language and Syntax : Queries : Alter Table

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

64 of 78 people (82%) answered Yes
Recently 5 of 10 people (50%) answered Yes

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;