页次: 1
使用 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
离线
页次: 1