Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL arrange existing table columns

Tags:

mysql

How can I change the position of a certain existing column in MySQL table?

Ex: I want to move the column username from its current position to instead be after all the columns or I want it before any certain column in my table.

like image 893
Barry Avatar asked Sep 28 '10 04:09

Barry


People also ask

How do I rearrange columns in MySQL table?

Go to Structure and click Move Columns and then just drag the columns to rearrange.

How do I rearrange columns in MySQL workbench?

Right-click the column and choose Move Up or Move Down .


2 Answers

You can change the order of columns if you like.

If your username column is varchar(255) then:

alter table `mytable`  change column username username varchar(255) after `somecolumn`; 

If it helps to better read a table definition, then why not?

like image 138
ceteras Avatar answered Sep 21 '22 18:09

ceteras


Thanks guys for all of your response, I'm already done with it.

ALTER TABLE tbl_user MODIFY gender char(1) AFTER username; 

Well it's just like organizing your table right? you don't want your primary key field to be on the last order of your table, at least I know how to coonfigure it if ever I encounter that problem, I'm trying to get used in text based database and not using gui for now.

Thanks again guys :)

like image 29
Barry Avatar answered Sep 24 '22 18:09

Barry