温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql数据库的索引类型

发布时间:2020-06-17 13:47:15 来源:PHP中文网 阅读:1019 作者:鸽子 栏目:MySQL数据库

索引类型介绍:

主键索引

primary key() 要求关键字不能重复,也不能为null,同时增加主键约束 主键索引定义时,不能命名

唯一索引

unique index() 要求关键字不能重复,同时增加唯一约束

普通索引

index() 对关键字没有要求

全文索引

fulltext key() 关键字的来源不是所有字段的数据,而是字段中提取的特别关键字

关键字:可以是某个字段或多个字段,多个字段称为复合索引。

实例:

建表:
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索引类型介绍的详细内容,更多请关注亿速云其它相关文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI