zoukankan      html  css  js  c++  java
  • 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;
    删除索引
  • 相关阅读:
    MYSQL router 自动均衡负载
    mysql router 自动failover测试
    Oracle数据库安装时 environment variable path 大于 1023
    windows删除多余启动引导项
    开机显示 invalid partition table
    有关软件的商业模式与软件代码的加密
    .Net 开源控件 NPlot使用小结
    41.关于Intellij IDEA菜单项中Compile、Make和Build的区别
    Maven:mirror和repository 区别
    28. Spring Boot配置方式
  • 原文地址:https://www.cnblogs.com/Neroi/p/10007651.html
Copyright © 2011-2022 走看看