• MySQL数据库之索引


    create table test1(
          id int primary key AUTO_increment,
          name varchar (20),
          salary int default  1000
    );
    insert into test1 (name)values ('111'),("222"),("333"),("444");
    
    select *from test1 where id=3;
    创建表和一般查询
    --唯一索引unique  唯一索引不可重复
    alter table test1 modify name varchar (20) unique;
    唯一索引

    --创建索引格式
    create table A(
    id int primary key,
    name varchar (20),
    unique|fulltext|spatial index|key [索引名] (字段名(长度)) [ASC|DESC]
    );
    --创建索引
    create table stu(
          id int,
          name varchar (20),
          index index_name (name)
          );
    创建索引
    --唯一索引(字段不能重复name)
    create table stu1(
          id int,
          name varchar (20),
          unique index index_name (name)
          );
    唯一索引
    --全文索引
    create table stu2(
      id int,
      name varchar (10),
      resume varchar (20),
      fulltext index index_resume (resume)
    );
    全文索引
    --创建多条索引
    create table stu3(
      id int,
      name varchar (10),
      resume varchar (20),
      index index_resume (name,resume)
    );
    创建多条索引
    create table t1(id int,name varchar (20));
    --修改结束符
    delimiter $$
    create procedure autoinsert()
    begin
    declare i int default 1;
    while(i<50)do
    insert into t1 values (i,"alex");
    set i=i+1;
    end while;
    end$$
    
    delimiter ;
    call autoinsert();
    脚本练习
    -- 添加索引
    -- create在已存在表上创建索引
    create [unique|fulltext|apatial] index index_name on table_name (字段名[(长度)]) [ASC|DESC];
    --alter table 在已存在表上创建索引
    alter table table_name add [unique|fulltext|apatial] index index_name (字段名[(长度)]) [ASC|DESC];
    添加索引
    --删除索引:
    drop index index_name on st1;
    删除索引
  • 相关阅读:
    springboot集成websocket
    验证regex表达式本身是否有问题
    Quartz Cron表达式 生成
    Cannot run program "python": CreateProcess error=2, 系统找不到指定的文件
    遇到多个构造器参数时,要考虑用构造器
    考虑使用静态工厂代替构造器
    idea自定义注释
    layui2.4.0前的table隐藏列
    002、获取屏幕大小
    001、关于TextView的一些小知识
  • 原文地址:https://www.cnblogs.com/Neroi/p/10007651.html
Copyright © 2020-2023  润新知