定义:
  索引是一种单独的、物理的对数据库表中一列或多列的值进行排序的一种存储结构
 
#为字段创建索引
#在表中的字段中创建索引
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

程序媛计划——mysql索引的更多相关文章

  1. 程序媛计划——mysql外键

    定义 外键:如果一个表的某个字段指向另一个表的主键,就称之为外键.被指向的表,称之为主表,也叫父表,那么另一个表就是从表,也叫子表 #先新建两个表 mysql> create table aut ...

  2. 程序媛计划——mysql连接表

    #inner join等值连接/内连接 mysql> select * from info; +------+-------------+----------+ | name | phone | ...

  3. 程序媛计划——mysql修改表结构

    #查看表的结构 mysql> desc score; +------------+--------------+------+-----+---------+----------------+ ...

  4. 程序媛计划——mysql 插入、查找、修改、删除数据

    #插入.查找数据 [mysql>create table if not exists exam_score( ..>id int(4) not null primary key auto_ ...

  5. 程序媛计划——mysql基本操作

    本文适用于mac 在官网上下载community 版mysql,选择dmy这种.在终端中安装好mysql. #进入mysql /usr/local/mysql/bin/mysql -uroot -p ...

  6. 程序媛计划——python socket通信

    定义 socket 是进程间的一种通信方式,可以实现不同主机间的数据传输 #写服务期端程序server.py #实现服务器向客户端连接 #!/usr/bin/env python #coding:ut ...

  7. 程序媛计划——python数据库

    #实例:用数据库存储日记,实现日记本功能 #流程 #创建数据库 #coding:utf-8 import sqlite3 connect=sqlite3.connect('test.db') conn ...

  8. 程序媛计划——SQLite初级

    数据库简介 数据库定义: 指的是以一定方式储存在一起.能为多个用户共享.具有尽可能小的冗余度.与应用程序彼此独立的数据集合.是带有相关数据的表的集合. 数据库是由行和列组成的二维表. 字段: 数据库表 ...

  9. 程序媛计划——python中级课时1

    class1 异常处理 #python会把标准输入的内容当作字符串处理,即使输入的是数字3也会转化为字符串’3’. n1 = raw_input() n2 = raw_input() print n1 ...

随机推荐

  1. linux下静默安装 weblogic12.2.1.3中间件

    第一步:准备需要的安装包文件,这里注意 weblogic12.2.*需要的最低JDK版本为1.8以上 1.查看当前的镜像列表:docker images 2.运行镜像,并进入容器,这里运行基本的cen ...

  2. discuz回贴通知插件实现-页面嵌入点(钩子)

    1.如何保证主题被回复时业务代码被执行. 2.获得主题,主题发布者,贴子等信息. 3.discuz发送email邮件.   discuz使用嵌入点(钩子)来处理代码的执行时机. 当用户开启插件开发者模 ...

  3. 有关gitlab的神秘操作.....version&&domain设置...

    在使用gitlab的时候,如果服务器IP变动,之前的domain写入了配置文件了,如下路径: [root@gitlab-server ~]# vim /var/opt/gitlab/gitlab-ra ...

  4. Linux 配置文件管理

    一.简介 参考:https://robots.thoughtbot.com/rcm-for-rc-files-in-dotfiles-repos http://dotfiles.github.io/ ...

  5. struts2用到的jar有那些

    struts2.0 lib/antlr-2.7.6.jarlib/struts2-core-2.0.14.jarlib/struts2-spring-plugin-2.0.14.jarlib/free ...

  6. 【commons-io】File对文件与目录的处理&FileUtis,IOUtils,FilenameUtils工具的使用

    -------------------File的使用-------------- 1.File类对文件的处理 1.1目录结构:  1.2测试对文件Test.txt处理: // 测试文件 @Test p ...

  7. css页面组件

    页面组件 1 元素的尺寸/边框/背景 1.1 css尺寸相关属性 height 高度 min-height 最小高度 max-height 最大高度 width 宽度 min-width 最小宽度 m ...

  8. 2018.09.11 poj1845Sumdiv(质因数分解+二分求数列和)

    传送门 显然需要先求出ab" role="presentation" style="position: relative;">abab的所有质因 ...

  9. gj6 深入python的set和dict

    6.1 collections中的abc from collections.abc import Mapping, MutableMapping #dict属于mapping类型 a = {} pri ...

  10. Python调用Google翻译

    出自:http://blog.csdn.net/zhaoyl03/article/details/8830806 最近想动手做一个文档自动下载器,需要模拟浏览器的行为.虽然感觉思路上没有困难,但在技术 ...