标签:建表 efault 索引 name 增删改 engine -- charset 创建
1 创建表时就指定索引
create table t1(
id int,
name char(5),
unique key nui_name(name),
primary key (id)
);
create table t2(
id int,
name char(5),
index idx_name(name)
);
2 在创建完表后为其添加索引
create table t3(
id int,
name char(5)
);
create inde idx_name on t3(name);
alter table t3 add index idx_id(id);
alter table t3 add primary key(id);
查看
mysql> show create table t3;
+-------+-------------------------------------
| Table | Create Table
+-------+-------------------------------------
| t3 | CREATE TABLE `t3` (
`id` int(11) DEFAULT NULL,
`name` char(5) DEFAULT NULL,
KEY `idx_name` (`name`),
KEY `idx_id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-------------------------------------
1 row in set (0.00 sec)
删除
drop index idx_id on t3;
alter table t3 drop primary key;
标签:建表 efault 索引 name 增删改 engine -- charset 创建
原文地址:http://www.cnblogs.com/djjv/p/7762669.html