索引是查询时才有用,索引必须独立存在。
索引的类型,查看索引,创建索引,索引底层长什么样子
1.主键也叫主索引
create table test2(id int primary key);
2.replace into demo(id,name,age) values(1,'王五',24);
select * from demo;
创建主键(索引)的方法1:create table test2(id int primary key);
创建主键(索引)的方法2:create table test3(id int, primary key(id));
创建普通索引:基本要求属性值是可以重复的只要是列就行
create index idx_name on demo(name);
show index from demo;
create table test4(id int,name varchar(10),
-> primary key(id),
-> unique(name)
-> );
show index from demo;
show index from test4;
insert into test4 values(1,'tom');
create table test5(id int,name varchar(10),
-> constraint mypri primary key(id),
-> constraint myuiq unique(name)
-> );
show index from test5;
alter table test5 drop primary key;
show index from test5;
alter table test5 drop index myuiq;
show index from test5;