数据库索引

数据库的索引

  1. 主键索引。
  2. 唯一索引:(unique or non_unique):键值不重复。
    • create unique index 索引名 on 表名(列名);
    • drop index 索引名;
  3. 全文索引。
  4. 普通索引:索引值:键值可以重复。
    • create index 索引名 on 表名(列名);
  5. 组合索引(composite):绑定了两个或更多列的索引。
    • create index 索引名 on 表名(列名1,列名2...);
    • drop index 索引名;
  6. 反向键索引(reverse):为了避免平衡树索引热块,比如emp表中很开头都是7,这样在构建索引树的时候很有可能把所有数据都分配到一个块里,使用反向键则使索引值反向,避免此类问题,使索引树的数据分布均匀。
    • create index 索引名 on 表名(列名) reverse;
    • drop index 索引名;
  7. 函数索引(function index):查询时必须要用到这个函数,才会使用到。
    • create index 索引名 on 表名(函数名(列名));
    • select * from 表名 where lower(ename)='scott';
    • drop index 索引名;
  8. 压缩索引(compress)。
    • create index 索引名 on 表名(列名) compress;
  9. 升序降序索引。
    • create index 索引名 on 表名(列名1 desc,列名2 esc);

添加索引

  1. 添加:
    1.1. 主键索引的添加:

    • 当创建一张表,将某个列设为设为主键的时候,则该列就是主键索引。
    • > create table 表名( id int unsigned primary key auto_increament,name varchar(30) not null default '') unsinged无符号位
      这是id列就是主键索引

    如果你在创建表时,没有指定主键索引,也可以在创建表后再添加。指令:
    alert table 表名 add primary key (列名)

    举例:
    create table 表名(id int,name varchar(30) not null default '');
    alert table 表名 add primary key (id);

    1.2. 普通索引
    一般来说,普通索引的创建,是先创建表,然后再创建普通索引。
    比如:
    create table 表名(id int unsigned,name varchar(30))

  2. 查询索引:
    2.1.

    • > desc 表名[该方法的缺点是:不能够显示索引名]。
    • > show index(es) from 表名。
    • > show keys form 表名。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值