zoukankan      html  css  js  c++  java
  • mysql_DML_索引、视图

    创建索引的语法格式:
    – 创建普通索引:
    • create index 索引名称 on 表名(列)
    • alter table 表名 add index 索引名称 (列)
    – 创建唯一索引:
    • create unique index 索引名称 on 表名(列名)
    • alter table 表名 add unique index 索引名称 (列)
    • 例子:
    – 给students 表的 phone加上唯一索引
    – Create unqiue index st_phone on students(phone);
    – 给students表的name加上普通索引
    – Create index st_name on students(name);
    – 给订单表中的订单状态和用户id加上组合索引
    – Create index status_user on orders(status,user_id);
    删除索引
    删除索引是指将表中已经存在的索引删除掉。一些不再
    使用的索引会降低表的更新速度,影响数据库的性能。对于
    这样的索引,应该将其删除。
    对应已经存在的索引,可以通过DROP语句来删除索引
    。基本形式如下:
    DROP INDEX 索引名 ON 表名 ;
    drop index complex_index on book;
    索引设计原则
    为了使索引的使用效率更高,在创建索引的时候必须考
    虑在哪些字段上创建索引和创建什么类型的索引。本小节将
    向读者介绍一些索引的设计原则。
    1.选择惟一性索引
    2.为经常需要排序、分组和联合操作的字段建立索引
    3.为常作为查询条件的字段建立索引
    4.限制索引的数目
    5.尽量使用数据量少的索引
    6.尽量使用前缀来索引
    7.删除不再使用或者很少使用的索引

  • 相关阅读:
    Boxes and Candies(贪心)
    Gone Fishing(贪心)
    Gaby Ivanushka(快排)
    Stacks of Flapjacks(栈)
    Robbery(记忆化搜索)
    PILE读书笔记_基础知识
    2. Add Two Numbers【medium】
    160. Intersection of Two Linked Lists【easy】
    92. Reverse Linked List II【Medium】
    206. Reverse Linked List【easy】
  • 原文地址:https://www.cnblogs.com/lingxia/p/5900900.html
Copyright © 2011-2022 走看看