关于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