当前位置:网站首页>MySQL - unique index
MySQL - unique index
2022-07-24 10:31:00 【Camellia Populus】
unique index
The so-called unique index , When creating an index , The field value of the restricted index must be unique . Through this type of index, you can query a record faster than ordinary index .
1. Define indexes when creating tables
CREATE TABLE tablename( propname1 type1, …… propnamen type..n, UNIQUE INDEX | KEY [indexname] (propnamen [(length)] [ ASC | DESC ] ) );Be careful :
Parameters UNIQUE INDEX and UNIQUE KEY Is used to specify a field as an index , Choose one of the two ;
Parameters indexname It's the index name , Omission ;
Parameters propnamen Is the name of the field corresponding to the index , This field must be the one defined earlier and must be defined as UNIQUE constraint ;
Parameters length Is an optional parameter , It refers to the length of the index , Must be a string type to use ;
Parameters ASC and DESC All optional parameters ,ASC Indicates ascending order ,DESC Represents a descending order , If you don't specify , In ascending order .mysql> create table class(id int, name varchar(64), teacher varchar(64), UNIQUE INDEX name_index(name)); // establish class surface , At the same time specified name Is a unique index column mysql> show create table class; // Query table structure mysql> insert into class values(1, ' Class one ', ' Zhang San '); // insert data 1 mysql> insert into class values(2, ' Class two ', ' Li Si '); // insert data 2 mysql> select * from class where id>0; // Query by column
2. Create an index on an existing table
Method 1 :CREATE UNIQUE INDEX indexname ON tablename (propname [(length)] [ASC|DESC]);
Method 2 :
ALTER TABLE tablename ADD UNIQUE INDEX | KEY indexname (propname [(length)] [ASC|DESC]);
边栏推荐
猜你喜欢

《nlp入门+实战:第二章:pytorch的入门使用 》

Curse of knowledge

Segment tree--

zoj-Swordfish-2022-5-6

The paper of gaojingjian center was selected into the ACL 2022 of the international summit to further expand the privacy computing capacity of Chang'an chain

MySQL - 索引的隐藏和删除

很佩服的一个Google大佬,离职了。。

Knapsack problem of dynamic programming -- three lectures on knapsack (01 knapsack, complete knapsack, multiple knapsack)

火山引擎:开放字节跳动同款AI基建,一套系统解决多重训练任务

Record AP and map calculation examples
随机推荐
A ten thousand word blog post takes you into the pit. Reptiles are a dead end [ten thousand word pictures]
MySQL - 多列索引
[electronic device note 3] capacitance parameters and type selection
Association Rules -- July 10, 2022
Simply use golang SQLC to generate MySQL query code
In depth analysis of common cross end technology stacks of app
Kotlin advanced
火山引擎:开放字节跳动同款AI基建,一套系统解决多重训练任务
The best time to buy and sell stocks (leetcode-121)
Rust tokio:: task:: localset running mode
Segment tree--
Dr. water 3
Basic SQL operations
Mysql database JDBC programming
MySQL - 唯一索引
Knapsack problem of dynamic programming -- three lectures on knapsack (01 knapsack, complete knapsack, multiple knapsack)
Common Unicode encoding range
脚手架内各文件配置说明、组件化开发步骤
JSON tutorial [easy to understand]
Sentinel 三种流控效果