zoukankan      html  css  js  c++  java
  • Mysql-索引

    index----索引(普通索引创建)
    
    ---------------例 show index from 表 (查看表的索引)
    
    ---------------例 create index 索引名 on 表(列名)  (创建普通索引)
    
    ---------------例 drop 索引名 on 表;(删除普通索引)
    
    create table in1(
        nid int not null auto_increment primary key,
        name varchar(32) not null,
        email varchar(64) not null,
        extra text,
        index ix_name (name)
    )
    普通索引
    unique----唯一的(唯一索引创建)
    
    ---------------例 create unique index 索引名 on 表名(列名);(创建唯一索引)
    
    ---------------例 drop unique index 索引名 on 表名;(删除唯一索引)
    
    create table in1(
        nid int not null auto_increment primary key,
        name varchar(32) not null,
        email varchar(64) not null,
        extra text,
        unique ix_name (name)
    )
    唯一索引
    ---------------例 alter table 表 add primary key(列);(创建主键索引)
    
    ---------------例 alter table 表 drop primary key;(删除主键索引)
    
    ---------------例 alter table 表名  modify  列名 int, drop primary key;(删除主键索引)
    
    
    create table in1(
        nid int not null auto_increment primary key,
        name varchar(32) not null,
        email varchar(64) not null,
        extra text,
        index ix_name (name)
    )
    
    OR
    
    create table in1(
        nid int not null auto_increment,
        name varchar(32) not null,
        email varchar(64) not null,
        extra text,
        primary key(ni1),
        index ix_name (name)
    )
    主键索引
    index(列1,列2) ---两列组合 --- 最左前缀
    
    ---------------例 create index ix_name_email on in3(name,email);(创建组合索引)
    
    ---------------例 select * from 表 where 列1 = 值   (走索引)
    
    ---------------例 select * from 表 where 列1 = 值 and 列2 = 值  (走索引)
    
    ---------------例 select * from 表 where 列2 = 值 (不走索引)
    
    
    create table in3(
        nid int not null auto_increment primary key,
        name varchar(32) not null,
        email varchar(64) not null,
        extra text
    )
    组合索引
    explain 查看执行过程
    
    const 不变的  通过explain查看执行过程的时候 type 的类型 是最快的,
    
    ---------------例 explain select * from 表 where 列=值;
    其他
  • 相关阅读:
    构建之法阅读笔记04
    学习进度条10
    描绘用户场景并将典型用户和用户场景描述
    学习进度条09
    构建之法阅读笔记03
    学习进度条08
    每日站立会议10(完成)
    每日站立会议09
    团队成员细节工作项估计
    JS实现全选、不选、反选
  • 原文地址:https://www.cnblogs.com/cloniu/p/6401662.html
Copyright © 2011-2022 走看看