当前位置:网站首页>Tutorial on principles and applications of database system (037) -- MySQL index (III): delete index
Tutorial on principles and applications of database system (037) -- MySQL index (III): delete index
2022-07-21 01:28:00 【Rsda DBA_ WGX】
Database system principle and Application Tutorial (037)—— MySQL The index of ( 3、 ... and ): Delete index
Catalog
If an index is not needed , You can delete . in addition , Once the index is created, it cannot be modified , But you can delete the index and recreate it , To achieve the purpose of modifying the index .
There are two ways to delete an index :(1) Use alter table command .(2) Use drop index command .
One 、 Delete index command
The syntax format of the delete index command is as follows :
ALTER TABLE Table name DROP INDEX Index name ;
-- or
DROP INDEX Index name ON Table name ;
Two 、 Use alter table Command delete index
The syntax is as follows :
ALTER TABLE Table name DROP INDEX Index name ;
for example :
1、 Create tables and indexes at the same time
/*
create table t51(
id int primary key auto_increment,
name char(20),
birth datetime,
salary int,
phone char(20),
email varchar(50),
index idx_name(name),
unique index uq_phone(phone),
index idx_name_email(name,email(10))
);
*/
mysql> create table t51(
-> id int primary key auto_increment,
-> name char(20),
-> birth datetime,
-> salary int,
-> phone char(20),
-> email varchar(50),
-> index idx_name(name),
-> unique index uq_phone(phone),
-> index idx_name_email(name,email(10))
-> );
Query OK, 0 rows affected (0.04 sec)
2、 See the table t51 Index in
mysql> show index from t51\G
*************************** 1. row ***************************
Table: t51
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: t51
Non_unique: 0
Key_name: uq_phone
Seq_in_index: 1
Column_name: phone
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 3. row ***************************
Table: t51
Non_unique: 1
Key_name: idx_name
Seq_in_index: 1
Column_name: name
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 4. row ***************************
Table: t51
Non_unique: 1
Key_name: idx_name_email
Seq_in_index: 1
Column_name: name
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 5. row ***************************
Table: t51
Non_unique: 1
Key_name: idx_name_email
Seq_in_index: 2
Column_name: email
Collation: A
Cardinality: 0
Sub_part: 10
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
5 rows in set (0.01 sec)
3、 Delete index idx_name_email
mysql> alter table t51 drop index idx_name_email;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show index from t51\G
*************************** 1. row ***************************
Table: t51
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: t51
Non_unique: 0
Key_name: uq_phone
Seq_in_index: 1
Column_name: phone
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 3. row ***************************
Table: t51
Non_unique: 1
Key_name: idx_name
Seq_in_index: 1
Column_name: name
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
3 rows in set (0.00 sec)
3、 ... and 、 Use drop index Command delete index
The syntax is as follows :
DROP INDEX Index name ON Table name ;
for example : Delete table t51 Index in uq_phone
mysql> drop index uq_phone on t51;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show index from t51\G
*************************** 1. row ***************************
Table: t51
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: t51
Non_unique: 1
Key_name: idx_name
Seq_in_index: 1
Column_name: name
Collation: A
Cardinality: 0
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
2 rows in set (0.00 sec)
边栏推荐
- acwing 869. 试除法求约数
- 裕华万宝风扇安装顺序
- cannot import name ‘import_string‘ from ‘werkzeug‘【bug解决】
- Day106. Shangyitong: data dictionary list, easyexcel, data dictionary import and export, integrated redis cache
- 音视频入门——H.264编码(宏块+片+帧)浅析
- 数据库系统原理与应用教程(027)—— MySQL 修改表中数据(三):改(update)
- Encapsulation, inheritance, polymorphism
- 二值化神经网络权重的分布规则
- DNS resolution process
- 洛谷 P1678 烦恼的高考志愿
猜你喜欢
百度飞桨EasyDL助力制造企业智能化转型
How can red star Macalline design cloud upgrade the traditional home furnishing industry in ten minutes to produce film and television level interior design effects
Blurred photos, second high-definition big picture, flying propeller ppde takes you to reproduce the image restoration model cmfnet
Dix minutes pour générer un effet de design intérieur de qualité film et télévision, comment mettre à niveau l'industrie de la maison traditionnelle avec Red Star McLaren Design Cloud
Baidu PaddlePaddle easydl helps manufacturing enterprises with intelligent transformation
How can mechanical manufacturing enterprises solve warehouse management problems with ERP system?
How to get started quickly in software testing
[probability and count]
通过TCP方式点灯
DNS domain name resolution
随机推荐
I want to display the number of records in the SQL database table on the label label
Question 128 of Li Kou: longest continuous sequence
Frontier and application of data security technology from the perspective of compliance
Unity shader shader learning (2)
Communication mode between processes
iptables防止nmap端口扫描
How to transfer a single node of the warehouse database to a cluster
Leetcode exercises grammar supplementary summary notes
JSON【代码演示详解,带你精通 JSON】
Create a file. If the superior (or superior, etc.) directory of the file does not exist, create the superior directory first, and then create the file
LeetCode_ 78_ subset
数据库系统原理与应用教程(025)—— MySQL 修改表中数据(一):增(insert)
Discussion on the new trend of network security technology
How can red star Macalline design cloud upgrade the traditional home furnishing industry in ten minutes to produce film and television level interior design effects
封装、继承、多态
Tutorial on principles and applications of database system (035) -- MySQL index (I): overview of index
Unity: PC development, click the object with the mouse to trigger the object to change the material
上次面试跪在了Redis上,刷完阿里表哥给的内部Redis文档,终面进大厂
机器学习练习 8 -异常检测和推荐系统(协同过滤)
数据库系统原理与应用教程(031)—— MySQL 的数据完整性(四):定义外键(FOREIGN KEY)