网站开发技术

记点笔记、 学点技术 欢迎交流建站技术。本站关注lamp技术

您尚未登录。

#1 2014-12-06 15:30:06

admin
管理员

mysql 已经创建好的表上, 创建索引。

使用 alter 先看一个例子:

格式:

alter table tb_name add [unique|fulltext] [index|key] [name] (field) [asc|desc]

示例:

mysql> create table tb2( name varchar(20));
Query OK, 0 rows affected (0.19 sec)

mysql> desc tb2;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> alter table tb2 add index (name) ;
Query OK, 0 rows affected (0.42 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc tb2;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(20) | YES  | MUL | NULL    |       |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.00 sec)



ipbbs.net

离线

页脚

Powered by FluxBB