Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does the MySQL unique index refer to

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about what the MySQL unique index refers to. 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.

When a new record is inserted into the data table, Mysql automatically checks to see if the value of this field of the new record has already appeared in this field of a record. If so, mysql will refuse to insert the new record.

In other words, the unique index can guarantee the uniqueness of the data record. In fact, in many cases, the purpose of creating unique indexes is not to improve access speed, but to avoid data duplication.

The method of creating a unique cable

Operation table

CREATE TABLE `wb_ blog` (`id` smallint (8) unsigned NOT NULL, `catid` smallint (5) blog`, `title`varchar (80) NOT NULL DEFAULT'', `content`blog`, PRIMARY KEY (`id`),)

To create a unique cable, you can use the keyword UNIQUE to create it with the table

Note: this is done in the command window mysql > CREATE TABLE `catename` (- > `id` smallint (8) unsigned NOT NULL,-> `catid` smallint (5) unsigned NOT NULL DEFAULT '0operations,-> `title`varchar (80) NOT NULL DEFAULT'',-> `content` text NOT NULL,-> PRIMARY KEY (`id`),-> UNIQUE KEY `catename` (`catid`)->); Query OK, 0 rows affected (0.24 sec)

The above code creates a unique index named catename for the 'catid' field of the wb_ blog table

2. After creating the table, use the CREATE command to create the

Mysql > CREATE UNIQUE INDEX catename ON wb_blog (catid); Query OK, 0 rows affected (0.47 sec)

If you do not need a unique index, you can delete it like this

Mysql > ALTER TABLE wb_blog DROP INDEX catename; Query OK, 0 rows affected (0.85 sec) Thank you for reading! On the MySQL unique index refers to what is shared 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.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report