mysql,索引

 索引:一般都是建表的时候都建好了。详细原理,视频位置 https://www.bilibili.com/video/av29072634/?p=5

    分类:
        主键索引:  不能重复。id    不能是null
        唯一索引  :不能重复。id    可以是null
        单值索引  : 单列, age ;一个表可以多个单值索引,name。
        复合索引  :多个列构成的索引 (相当于 二级目录 :  z: zhao)  (name,age)   (a,b,c,d,...,n)
    创建索引:
        方式一:
        create 索引类型  索引名  on 表(字段)
        单值:
        create index   dept_index on  tb(dept);
        唯一:
        create unique index  name_index on tb(name) ;
        复合索引
        create index dept_name_index on tb(dept,name);

        方式二:alter table 表名 索引类型  索引名(字段)
        
        单值:
        alter table tb add index dept_index(dept) ;
        唯一:
        alter table tb add unique index name_index(name);
        复合索引
        alter table tb add index dept_name_index(dept,name);

        注意:如果一个字段是primary key,则改字段默认就是 主键索引    
    

        删除索引:
        drop index 索引名 on 表名 ;
        drop index name_index on tb ;

        查询索引:
        show index from 表名 ;
        show index from 表名 \G

SQL优化(暂无)

猜你喜欢

转载自www.cnblogs.com/javalbb/p/11416878.html