Home > Database > Mysql Tutorial > How to change the order of columns in mysql

How to change the order of columns in mysql

coldplay.xixi
Release: 2020-11-03 10:12:44
Original
10934 people have browsed it

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].

How to change the order of columns in mysql

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
Copy after login

How to change the order of columns in mysql

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;
Copy after login

How to change the order of columns in mysql

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;
Copy after login

How to change the order of columns in mysql

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template