mysql索引类型介绍


本文摘自PHP中文网,作者V,侵删。

索引类型介绍:

主键索引

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

唯一索引

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

普通索引

index() 对关键字没有要求

全文索引

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

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

实例:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

建表:

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索引类型介绍的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

关于mysql explain中key_len的计算方法讲解

mysql引擎有哪些

mysql如何更改连接端口

mysql自增健有什么用?

mysql怎样改变某一列的数据类型

mysql中如何配置ssl_key和ssl-cert与ssl-ca的路径以及建立ssl连接的实例

mysql利用子查询效率怎么样

mysql router怎么样

mysql 中,如何计算一组数据的中位数

sql中关于distinct关键字的四种用法

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...