Home >Database >Mysql Tutorial >How to change the order of columns in mysql
Mysql method to change the column order: first open the data table; then put the id in front, and the data does not move, the syntax is [alter table table name modify field name field type after field].
Mysql method to change the column order:
I created a data table like this and want to put the id in The first column, because it is the primary key and is auto-incrementing:
mysql> select * from student
The original order is as shown above. How can I put the id in front and the data does not move? What about properties that remain unchanged? Without further ado, let’s go straight to the sentence:
alter table table name modify field name field type after field
mysql> alter table student modify id int(10) unsigned auto_increment first;
This is Put it first, what if you want to put the name after the id? Just write it like this (just replace first with after):
mysql> alter table student modify name varchar(10) after id;
Extension part:
You can also use the change method Modify
Adjust the field order:
alter table table name change field name new field name field type default value after field name (jump to which field after)
Example:
alter table t1 change z1 rename_z1 varchar(50) default null AFTER z5
More related free learning recommendations: mysql tutorial(Video)
The above is the detailed content of How to change the order of columns in mysql. For more information, please follow other related articles on the PHP Chinese website!