In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly tells you how to add an index to mysql. You can look up the relevant professional terms on the Internet or find some related books to supplement them. Here, we will not dabble in, go straight to the topic, and hope to bring you some practical help.
1. Add PRIMARY KEY (primary key index)
Mysql > ALTER TABLE `table_ name` ADD PRIMARY KEY (`column`)
2. Add UNIQUE (unique index)
Mysql > ALTER TABLE `table_ name` ADD UNIQUE (`column`)
3. Add INDEX (general 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`)
Here is a more detailed approach
The alter table SQL statement can be used in MySQL to add indexes to the fields in the table.
The basic syntax for using the alter table statement to index fields in a table is:
ALTER TABLE ADD INDEX ()
Example: let's try to add an index to the t_name field in test.
Mysql > alter table test add index (t_name); Query OK, 0 rows affected (0.17 sec) Records: 0 Duplicates: 0 Warnings: 0
After the implementation is successful, let's take a look at the results.
Mysql > describe test +-+ | Field | Type | Null | Key | Default | Extra | + -+-+ | t_id | int (11) | YES | | NULL | | t_name | varchar (50) | NO | MUL | NULL | | t_password | char (32) | YES | | NULL | | t_birth | date | YES | | NULL | | +-| +-+ 4 rows in set (0.00 sec)
As a result, you can see that the Key column of the t_name field has changed from blank to MUL. What does this MUL mean? To explain briefly: if Key is MUL, then the value of the column can be repeated, and the column is the leading column of a non-unique index (the first column) or part of a unique index but can contain a null value of NULL.
Mysql is how to add the index to tell you here, for other related issues you want to know the industry information that you can continue to follow. Our section will capture some industry news and professional knowledge to share with you every day.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.