zoukankan      html  css  js  c++  java
  • 程序媛计划——mysql索引

    定义:
      索引是一种单独的、物理的对数据库表中一列或多列的值进行排序的一种存储结构
     
    #为字段创建索引
    #在表中的字段中创建索引
    mysql> create index ind_score on score(name); Query OK, 0 rows affected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0 #查看索引 mysql> show index from score; +-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | score | 0 | PRIMARY | 1 | id | A | 4 | NULL | NULL | | BTREE | | | | score | 1 | ind_score | 1 | name | A | 4 | NULL | NULL | | BTREE | | | +-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 2 rows in set (0.00 sec)

    #也可以在创建表的时候创建索引

    #删除索引

    mysql> drop index ind_score on score;
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    #用alter创建/删除索引

    mysql> alter table score add index ind_score(name);
    Query OK, 0 rows affected (0.02 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> alter table score drop index ind_score;
    Query OK, 0 rows affected (0.01 sec)
    Records: 0  Duplicates: 0  Warnings: 0

    #创建索引值唯一的索引(好处是数据很多时能通过唯一索引快速查询到数据)

    mysql> create unique index uni_index on score(score);
    Query OK, 0 rows affected (0.02 sec)
    Records: 0  Duplicates: 0  Warnings: 0
  • 相关阅读:
    深入理解CSS中的margin负值
    深入理解CSS浮动
    深入理解CSS绝对定位
    深入理解display属性
    JAVA-初步认识-第四章-内存空间的划分&栈内存&堆内存
    JAVA-初步认识-第四章-数组-概述和定义
    JAVA-初步认识-第四章-重载练习
    JAVA-初步认识-第四章-重载
    JAVA-初步认识-第四章-函数-内存加载过程
    JAVA-初步认识-第一章-整体的认识
  • 原文地址:https://www.cnblogs.com/IcarusYu/p/7497716.html
Copyright © 2011-2022 走看看