I want to change the column positions of my database table without losing data.
我希望在不丢失数据的情况下更改数据库表的列位置。
For example:
例如:
Current table:
当前表:
+----+------+-------+----------+
| id | name | email | password |
+----+------+-------+----------+
to
来
+----+----------+------+-------+
| id | password | name | email |
+----+----------+------+-------+
3 个解决方案
#1
74
Try it like this:
试试这样:
ALTER TABLE table_name MODIFY password varchar(20) AFTER id
修改表table_name修改id后的密码varchar(20)
#2
#3
1
If you are using MySQL workbench,
如果您正在使用MySQL workbench,
- Right-click on table
- 右键单击表
- Alter table
- Alter table
- drag columns and re-order
- 拖动列和再订购
- click apply and finish
- 单击apply,完成
#1
74
Try it like this:
试试这样:
ALTER TABLE table_name MODIFY password varchar(20) AFTER id
修改表table_name修改id后的密码varchar(20)
#2
11
Hearaman's answer is correct; but if you are using phpMyAdmin, there is a visual and practical way to do that.
Hearaman的回答是正确的;但是,如果您正在使用phpMyAdmin,那么有一种可视化和实用的方法可以实现这一点。
- Open the table
- 打开表
- Choose the "Structure" tab
- 选择“结构”选项卡
- Click on "Move columns"
- 点击“列”
- Drag and drop column names
- 拖放列名。
#3
1
If you are using MySQL workbench,
如果您正在使用MySQL workbench,
- Right-click on table
- 右键单击表
- Alter table
- Alter table
- drag columns and re-order
- 拖动列和再订购
- click apply and finish
- 单击apply,完成