In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How to modify the table structure of MySQL database? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!
MySQL database to modify the table structure methods: 1, use add to add fields, use drop to delete fields; 2, use alter to modify field names; 3, modify column types; 4, modify table names; 5, modify table options; 6, modify column properties.
[related graphic tutorials: mysql database graphic tutorials]
The method of modifying the table structure of MySQL database:
1. Add and delete fields
(1), add
Alter table table name add [column] field name column type column attribute [first | after field name]
(2), delete
Alter table table name drop [column] field name
two。 Modify field name
Statement: alter table table name change original field name new field name column type column attribute
Note: even if you only change the field name, then the original type of the field, the original property should be rewritten, otherwise it will be deleted.
3. Modify column type
Statement: alter table table name modify field name column type column attribute
4. Modify table name
Statement: alter table table name rename to new table name
5. Modify table options
Statement: alter table table name table option
Description: although MYSQL provides commands to modify table options, do not execute the command to modify the character set if there is already data in a table.
6. Modify column properties
Column properties include not null, default, unique, primary key, auto_increment
When a table is created, we can use the alter table table name modify to manipulate column properties. If the column properties are written during the operation, the
Is to add column properties, if not written is to delete column properties.
Special column properties: Primary key and unique.
Add column properties
Increase in general attributes:
Statement: alter table table name modify field name column type column attribute
Description:
When adding An and auto_increment, you should note that the field must be an integer, and it must be unique or primary key.
B, Unique and default cannot be used together.
The addition of primary key attributes:
Statement: alter table table name add primary key (field name)
Thank you for reading! After reading the above, do you have a general understanding of the method of modifying the table structure of the MySQL database? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are 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.