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)06/01 Report--
This article is about how mysql changes the properties of the primary key. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
Mysql changes the primary key attributes: 1, use the keyword modify, the code is [alter table tbl_name modify.]; 2, use the keyword change, the code is [alter table tbl_name change..].
How mysql changes the properties of the primary key:
1. Add a primary key constraint:
Alter table tbl_name add primary key (index_col_name, …) ; # is the field name in parentheses, which can be one or more
two。 If the datasheet already exists and there is no primary key, add a new field as the primary key and move the field to the first column of the table
Alter table tbl_name add col_name col_definition (data type, null, default...) Primary key first current_first_col_name;# current_first_col_name represents the first column of the current data table
Notes: the keyword first indicates that it is in front of a column. If the added field needs to be after a column, you can use after.
3. The datasheet already exists and has a primary key. Modify the definition of the primary key.
Keyword modify
Alter table tbl_name modify col_name col_definition [first | after col_name] # declare the attributes to be modified in col_definition, such as adding automatic numbering auto_increment
Notes:
1) there is no need to redeclare the primary key attribute primary key at this time. If it is added, an error will be reported: the primary key is duplicated.
2) if auto_increment exists in the original attribute, you need to add auto_increment when modifying it, otherwise the auto_increment attribute will be deleted.
Keyword change
The difference between alter table tbl_name change col_name col_name col_definition [first | after col_name] # and modify is that the list needs to write the column name twice, which is equivalent to the original column name and the new column name, so change can also be used to modify the column name. Thank you for reading! On mysql to change the primary key properties of the method to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
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.