Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How mysql changes the order of columns

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces mysql how to change the order of columns, the article is very detailed, has a certain reference value, interested friends must read it!

Mysql changes the order of the columns by first opening the data table, and then putting id in front of the data, with the syntax [alter table table name modify field name field type after field].

Mysql's method of changing the order of columns:

Create a data table like this and want to put id in the first column because it is a primary key and is self-incrementing:

Mysql > select * from student

The original order is shown above, how to put id in front, and the data does not move, the attributes remain the same? Don't talk too much nonsense, just put on 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 the first place. What if you want to put name after id? Just write it this way (first can be replaced with after):

Mysql > alter table student modify name varchar (10) after id

Extension:

You can also modify it using change.

Adjust the order of the fields:

Alter table table name change field name new field name field type default after field name (after which field to skip)

Example:

Alter table T1 change Z1 rename_z1 varchar (50) default null AFTER Z5 and above is all about how mysql changes the order of the columns. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report