MySQL 如何在不丢失列数据的情况下更改MySQL表的列位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10718905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:30:08 来源:igfitidea点击:
How to change the column position of MySQL table without losing column data?
提问by D S
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 |
+----+----------+------+-------+
回答by Hearaman
Try this:
尝试这个:
ALTER TABLE table_name MODIFY password varchar(20) AFTER id
回答by Arman Ozak
回答by Mohemmed Niyaz
If you are using MySQL workbench,
如果您使用的是 MySQL 工作台,
- Right-click on table
- Alter table
- drag columns and re-order
- click apply and finish
- 右键单击表
- 改变表
- 拖动列并重新排序
- 单击应用并完成
回答by jundev
Also, you can do it like this:
此外,你可以这样做:
ALTER TABLE table_name CHANGE COLUMN column_name column_name data_type AFTER another_column_name;