關於Mysql唯一索引的操作方法(添加刪除)


    首先我們查看一下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;

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM