In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you how to modify the mysql table field, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
First create a database, as well as several tables (one table is also fine). Before the article opened, I created a database called student, as well as a data table for stu, all of which are based on this table.
Modify table field type
After table table name modify [colimn] field definition [first | names of fields]
Mysql > after table stu modify column name varchar
In this way, the name field in the stu table can be modified to be of type varchar.
Add table field
After table table name add [colimn] field definition [first | names of fields]
Mysql > after table stu add column sex varchar
After executing the above statement, when we use desc to view the form, we find that there is an extra field of sex, indicating that we have successfully added the field.
Delete table field
After table table name drop [colimn] field name
Mysql > after table stu drop sex
We can see that the field that was just added has now been deleted, and there is no sex field.
Rename the field
After table table name change [colimn] Old field name field definition [first | "field name]
Mysql > after table stu change name mingzi varchar
In this way, you can rename the original name field to mingzi, and you can also use this method if you want to change the field type instead of the field name.
Mysql > after table stu change mingzi mingzi char
This allows you to modify the field type without changing the field name.
Note: both change and modify can modify the definition of the table, but the difference is that change needs to be followed by two column names, which is not particularly convenient. The advantage is that change can modify field names.
Modify field arrangement sort
[first | after field name] this selection can be used to modify the position of the field in the table. By default, the new field is loaded in the last position in the table, while change/modify does not change the field location by default.
Note: change/first | after field name these keywords belong to the extension of mysql on standard sql and may not be applicable to other databases.
Change the table name
After table table name rename [to] New table name
Mysql > after table stu rename students
So we can change the name of the data table.
The above is all the contents of the article "how to modify mysql Table Fields". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.