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 |
+----+----------+------+-------+
试试这个:
ALTER TABLE table_name MODIFY password varchar(20) AFTER id
If you are using MySQL workbench,
此外,你可以这样做:
ALTER TABLE table_name CHANGE COLUMN column_name column_name data_type AFTER another_column_name;
You can use modify/change keyword.
ALTER TABLE [table] CHANGE COLUMN [column] [column] [column definition] AFTER [column]
ALTER TABLE [table] MODIFY COLUMN [column] [column definition] AFTER [column]
Eg:
ALTER TABLE table_name MODIFY password varchar(20) AFTER id
ALTER TABLE table_name MODIFY password varchar(20) varchar(20) AFTER id
Another method if you are using MySQLWorkbench,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.