首先我們查看一下News數據表的索引信息
使用命令 show index from ‘數據表名稱’;
目前數據表中僅有一個主鍵索引
繼續,我們給news表添加兩個唯一索引(兩種方法)
方法一: alter table '數據表名' add constraint '索引名' unique(‘要添加的字段名’);
alter table news add constraint title_sy unique(title);
方法二:create unique index 索引名 on 數據表名(字段名);
create unique index http_sy on news(http);
添加完索引之后,我們查看一下剛才添加的兩個索引是否存在--->
下面我們給News表刪除索引 (兩種方法)
方法一: alter table 數據表名 drop index 刪除的索引名;
alter table news drop index title_sy;
方法二: drop index 索引名 on 數據表名;
drop index http_sy on news;
最后,檢查一下是否刪除了
show index from news;