In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to use the alter sentence in mysql. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
1)。 Modify the table name:
Mysql > ALTER TABLE test RENAME TO test_old
2)。 Increase primary key
Mysql > alter table tabelname add new_field_id int (10) unsigned default 0 not null auto_increment, add primary key (new_field_id)
Change ID to self-increment and set it as primary key
Mysql > alter table brand_title_temp_noread modify id int auto_increment primary key
3)。 Column actions:
Add fields:
Mysql > ALTER TABLE table_name ADD field_name field_type
Mysql > ALTER TABLE search_record ADD `send` INT default 0
4)。 Modify the field type:
Mysql > alter table search_record alter column big set default 0
5)。 Add a field after a field:
Mysql > alter table `user_movement_ log` Add column GatewayId int not null default 0 AFTER `Regionid`
6)。 Adjust the order of the fields:
Mysql > alter table `user_movement_ log` CHANGE `GatewayId` `GatewayId` int not null default 0 AFTER RegionID
7)。 Modify the original field name and type:
Mysql > alter table table_name CHANGE old_field_name new_field_name field_type
Mysql > ALTER TABLE manual_record CHANGE `Note- sort``Note_ sort` varchar (50) DEFAULT NULL
Modify the field type:
Mysql > alter table scholar_keys change hold hold int default 0
Delete a field:
Mysql > ALTER TABLE table_name DROP field_name
Modify a field
Mysql > alter table user MODIFY new1 VARCHAR (10); / / modify the type of a field
Mysql > alter table manual_record MODIFY `ORGANIZATION `VARCHAR (500) DEFAULT NULL
Mysql > alter table user CHANGE new1 new4 int; / / modify the name of a field. Be sure to reassign the field type at this time.
8)。 Index operation:
1. Add PRIMARY KEY (primary key index)
Mysql > ALTER TABLE `table_ name` ADD PRIMARY KEY (`column`)
two。 Add UNIQUE (unique index)
Mysql > ALTER TABLE `table_ name` ADD UNIQUE (`column`)
3. Add INDEX (normal index)
Mysql > ALTER TABLE `table_ name` ADD INDEX index_name (`column`)
4. Add FULLTEXT (full-text index)
Mysql > ALTER TABLE `table_ name` ADD FULLTEXT (`column`)
5. Add multi-column index
Mysql > ALTER TABLE `table_ name` ADD INDEX index_name (`column1`, `column2`, `column3`)
On how to use the alter statement in mysql to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.