Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rearrange MySQL columns?

Tags:

mysql

I need to move the position of existing columns (for better visibility).

How can this be done without affecting the data?

like image 259
Yeti Avatar asked May 29 '10 08:05

Yeti


People also ask

How do I change the order of columns in MySQL workbench?

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

How do I change the order of data in MySQL?

An "ALTER TABLE ORDER BY" statement exist in the syntaxes accepted by MySQL. According to the documentation, this syntax: - only accept *one* column, as in "ALTER TABLE t ORDER BY col;" - is used to reorder physically the rows in a table, for optimizations.


2 Answers

Modify also works. Have a look:

ALTER TABLE foo MODIFY bar bartype AFTER baz; 
like image 127
vkGunasekaran Avatar answered Sep 19 '22 17:09

vkGunasekaran


The only way I know is to change the column. You would first extract your column definition using SHOW CREATE TABLE and issue an ALTER TABLE:

ALTER TABLE foo CHANGE COLUMN bar bar COLUMN_DEFINITION_HERE FIRST; 

Or if you want it after a certain other column:

... AFTER OTHER_COLUMN; 
like image 41
soulmerge Avatar answered Sep 20 '22 17:09

soulmerge