MySQL arrange existing table columns

前端 未结 6 533
鱼传尺愫
鱼传尺愫 2021-01-30 03:35

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

6条回答
  •  逝去的感伤
    2021-01-30 04:29

    ALTER TABLE [tbl_name] MODIFY|CHANGE [column definition] [AFTER|BEFORE] [a_column] both would work. MODIFY would be preferable if you only want to change column order but not renaming. Also, you CANNOT combine multiple columns reordering in a single ALTER TABLE statement. I.E. to rearrange integer columns col1, col2, col3 order to be in the order of col3, col2, col1, you will have to do

    ALTER TABLE tbl_name MODIFY col3 int FIRST; ALTER TABLE tbl_name MODIFY col2 int AFTER col3;

提交回复
热议问题