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;