You Are Here Home > How to move a column’s position in a MySQL table

How to move a column’s position in a MySQL table

You can move a column in a MySQL table to another position like this:

ALTER TABLE name_of_the_table MODIFY column_to_move tinyint(1) DEFAULT '0' AFTER column_to_move_after

Note: the part with: “tinyint(1) default ’0′” is necessary and it should be the exact definition of your column.
For example yours might be:
int(10) unsigned NOT NULL auto_increment
or
int(10) unsigned NULL default ’0′
or

How to move a column’s position in a MySQL table
Filed under: MySQL,Web Development   Posted by: Hamid

4 Comments »

  1. Anonymous:
     

    …but how does one move a column to the TOP of the table? So it is the first column?

    Comment

     
  2. Codehead:
     

    Here it is:
    http://codingrecipes.com/database-servers/mysql-rearrange-move-mysql-table-columns

    Comment

     
  3. Illusive:
     

    To move the column to the top you would place it behind the one on top, then move the one on top below the 2nd.
    Simple using the above SQL command.

    Comment

     
  4. Muaddub:
     

    You can use the FIRST keyword.

    ALTER TABLE name_of_the_table MODIFY column_to_move tinyint(1) DEFAULT ’0′ FIRST

    Comment

     

RSS feed for comments on this post. TrackBack URL

Leave a comment