作者:不会游泳的鱼 | 来源:互联网 | 2020-09-12 22:54
mysql索引类型:1、主键类型,关键字不能重复,也不能为null;2、唯一索引,关键字不能重复,同时增加唯一约束;3、普通索引,index()对关键字没有要求;4、全文索引。
建表:
creat table student(
stu_id int unsigned not null auto_increment,
name varchar(32) not null default '',
phone char(11) not null default '',
stu_code varchar(32) not null default '',
stu_desc text,
primary key ('stu_id'), //主键索引
unique index 'stu_code' ('stu_code'), //唯一索引
index 'name_phone' ('name','phone'), //普通索引,复合索引
fulltext index 'stu_desc' ('stu_desc'), //全文索引) engine=myisam charset=utf8;
更新:
alert table student add primary key ('stu_id'), //主键索引
add unique index 'stu_code' ('stu_code'), //唯一索引
add index 'name_phone' ('name','phone'), //普通索引,复合索引
add fulltext index 'stu_desc' ('stu_desc'); //全文索引删除:
alert table sutdent
drop primary key,
drop index 'stu_code',
drop index 'name_phone',
drop index 'stu_desc';
推荐教程:mysql教程
以上就是mysql索引类型介绍的详细内容,更多请关注 第一PHP社区 其它相关文章!