zoukankan      html  css  js  c++  java
  • MySQL创建索引

    一.在建立表时建立索引

    在建立表时创建索引的语法:

    create table 表名(

    列名1  列名1属性....

    列名2  列名2属性....

    列名 列名的属性

    【UNIQUE(唯一性的约束)|FULLTEXT(全文索引)|SPATIAL(空间索引)】INDEX|KEY 【别名】(属性名 【长度】【ASC|DESC】

    );

    INDEX|KEY 【别名】(属性名 【长度】【ASC|DESC】注解:

    使用index或者是key来指定一个字段索引,同时也可以给索引指定别名。

    长度:只有字符串类型才可以指定索引的长度。

    asc/desc:排序

    1.1.创建普通索引

    创建普通的索引,不添加UNIQUE和FULLTEXT等任何参数

    例子:

    use study;
    create table sorc(
    s_id int primary key,
    s_name varchar(10),
    index indexs (s_id desc)
    );

    那么现在这个indexs就是一个普通索引。

    1.2.创建唯一性索引

    就是在index前面加上修饰词unique

    例子:

    use study;
    create table sorc1(
    s_id int primary key,
    s_name varchar(10),
    unique indexs (s_id desc)
    );

    现在就有一个唯一性索引indexs了

    1.3.创建全文索引

    就是在index前面加上修饰词fulltext,但是需要注意只有char和varchar以及text类型才支持。否者就会报错如下:

    1.4.创建多列索引

    在一个括号中用“,”分开列名即可。

     例子:

    use study;
    create table if not exists sorc4 (
    s_id int primary key,
    s_name varchar(10),
    unique indexs (s_id,s_name)
    );

     现在就有两个索引了。

    二.在已有的表中去建立索引

     在已有的表中建立索引的语法:

     create 【unique|fulltext|spatial】index 索引名 on  表名(长度 【ASC|DESC】);

     例子:

    create unique index index_id on sorc4(s_id);

     三.删除索引

     语法:drop  index  索引名  on  表名;

     例子:

    drop index index_id on sorc4;
  • 相关阅读:
    OSCP Learning Notes Buffer Overflows(3)
    OSCP Learning Notes Buffer Overflows(5)
    OSCP Learning Notes Exploit(3)
    OSCP Learning Notes Exploit(4)
    OSCP Learning Notes Exploit(1)
    OSCP Learning Notes Netcat
    OSCP Learning Notes Buffer Overflows(4)
    OSCP Learning Notes Buffer Overflows(1)
    OSCP Learning Notes Exploit(2)
    C++格式化输出 Learner
  • 原文地址:https://www.cnblogs.com/SAM-CJM/p/9681422.html
Copyright © 2011-2022 走看看