当前位置:网站首页>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]);
边栏推荐
- 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
- [carving master learning programming] Arduino hands-on (59) - RS232 to TTL serial port module
- Implementation and traversal of binary tree and binary tree sorting tree
- Homologous policy solutions
- fatal: unable to commit credential store: Device or resource busy
- 2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1
- 高精尖中心论文入选国际顶会ACL 2022,进一步拓展长安链隐私计算能力
- String__
- Create a vertical seekbar from scratch
- 脚手架内各文件配置说明、组件化开发步骤
猜你喜欢

Adobe Substance 3D Designer 2021软件安装包下载及安装教程

2022, enterprise unified process platform design and integration specifications refer to thubierv0.1

The best time to buy and sell stocks (leetcode-121)

NIO知识点

PC博物馆(1) 1970年 Datapoint 2000

Dynamic planning: robbing families and houses

差分约束系统---1且2--2022年5月27日

New:Bryntum Grid 5.1.0 Crack
![[correcting Hongming] what? I forgot to take the](/img/41/c8fa6380ab63949ae6d904fdbb005c.png)
[correcting Hongming] what? I forgot to take the "math required course"!

WEB安全基础 - - -文件上传(文件上传绕过)
随机推荐
The optimal time to buy and sell stocks includes the freezing period (leetcode-309)
How does ribbon get the default zoneawareloadbalancer?
How many indexes are associated indexes under MySQL InnoDB?
2022, will lead the implementation of operation and maintenance priority strategy
pom文件dependency中的 scope用法
Web Security Foundation - file upload (file upload bypass)
Segment tree--
Sentinel 流量控制快速入门
Erlang studies abroad
[recommendation system] the classic technical architecture of the data flow of the recommendation system + the most complete evolution map of the top 10 deep learning CTR models of Microsoft, Alibaba,
Sentinel 三种流控模式
PyTorch 常用 Tricks 总结
The best time to buy and sell stocks includes handling charges (leetcode-714)
第五章 修改实现(IMPL)类
Erlang learning 01
[sword finger offer II 115. reconstruction sequence]
Figure model 2-2022-5-13
【LeeCode】获取2个字符串的最长公共子串
757. Set the intersection size to at least 2: greedy application question
2022, enterprise unified process platform design and integration specifications refer to thubierv0.1