How to rearrange MySQL columns?

前端 未结 5 1519
闹比i
闹比i 2020-12-01 03:35

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

How can this be done without affecting the data?

5条回答
  •  日久生厌
    2020-12-01 04:03

    Here is the sql query
    ALTER TABLE table_name MODIFY COLUMN misplaced_column Column-definition AFTER other_column; Here in Column-definition is full column definition. To see the column definition if you are using phpmyadmin click on structure tab. Then click on change link on desired column. Then withour modifyig any things click save. It will show you the sql. Copy the sql and just add *AFTER other_column* at the end. It will be all.

    If you like to bring the *misplaced_column* to the first position then ALTER TABLE table_name MODIFY COLUMN misplaced_column Column-definition FIRST;

    However, It seems it is a duplicate question.

提交回复
热议问题