索引

二、索引分类
1、主键索引 (primary key/pri)
一个表中只能由有一个,不能为空,唯一
添加主键: ALTER table 表名add PRIMARY key(字段名)
如: ALTER table 表名add PRIMARY key(id)
2、唯一索引 (unique /uni)
一个表中可以有多个,能为空,唯一
ALTER table 表名 add UNIQUE 索引名(字段名)
如:alter table s2 add UNIQUE sym(name)
3、普通索引 (mull)
最基本的索引,没有任何限制
alter table 表名 add index 索引名)字段名)
如:alter table s3 add index sym(id)
三、索引
1,查看表中的索引:
show index from 表名
shou keys from 表名
e02b5e04c3b938842cce7fa5d959780e

2、查看索引简写:
desc 索引名
3、删除表中索引:(普通索引和唯一索引)
ALTER table 表名 drop index sym;
4、删除主键索引
ALTER table 表名 drop PRIMARY key;
四、约束
默认值:default
不为空:not null
自增长:auto_increment 一般和主键一起使用
主键:primary key
唯一:unique
建表:create table x1(id int(10) PRIMARY key auto_increment,name varchar(20) UNIQUE ,
sex int(10) not null ,age int(10) DEFAULT 18)DEFAULT CHARSET=utf8
select * from x1 ;
desc x1
7753d2a998ee8139068f037f4ff79395

1、什么是索引?
2、索引的作用?
3、如何创建索引?
4、主键索引和唯一索引的区别?

posted @ 2026-01-23 14:48  plum/  阅读(1)  评论(0)    收藏  举报