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;
删除索引

转载于:https://www.cnblogs.com/Neroi/p/10007651.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值