從 MySQL 表格中移除索引
若要從 MySQL 表格中移除索引,語法如下 −
alter table yourTableName drop index `yourIndexName`;
我們先建立一個表格 −
Mysql> create table DemoTable1469 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(40), -> StudentAge int -> ); Query OK, 0 rows affected (0.78 sec)
以下是向列名稱新增索引的查詢 −
mysql> create index `Student Name_Index` on DemoTable1469(StudentName); Query OK, 0 rows affected (0.33 sec) Records: 0 Duplicates: 0 Warnings: 0
讓我們查看錶格描述 −
mysql> desc DemoTable1469;
它將生成以下輸出 −
+-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(40) | YES | MUL | NULL | | | StudentAge | int(11) | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
以下是移除索引的查詢 −
mysql> alter table DemoTable1469 drop index `Student Name_Index`; Query OK, 0 rows affected (0.23 sec) Records: 0 Duplicates: 0 Warnings: 0
讓我們再次查看錶格描述 −
mysql> desc DemoTable1469;
它將生成以下輸出 −
+-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(40) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
廣告