如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
一次插多条
1 2 3 4 5 6 7 8 9 |
create table t11( id tinyint(4) not null primary key auto_increment, name varchar(20) not null )engine=innodb default charset=utf8; insert into t11 values (1,'xx'), (2,'cc'); |
修改字段
alter table 表名 change 要修改的字段名 改后的字段名
1 2 |
varchar(20) not null; |
modify只能修改字段的属性不能修改字段名称
1 2 |
alter table t11 change name username varchar(10); |
添加字段
alter table 表名 add 字段名
1 2 3 |
varchar(20) not null default 'aa'; alter table t11 add sex enum('男','女'); |
删除字段
alter table 表名 drop 字段名;
1 2 |
alter table t11 drop sex; |
修改表名
rename table 原名 to 新名;
1 2 |
rename table t11 to t121; |
Alter table 表的旧名称 rename as 表的新名称;
1 2 |
alter table t121 rename as t11; |
删除主键索引 (先去除自增再删除)
1 2 3 |
alter table t11 change id id int(8) unsigned; alter table t11 drop primary key; |
添加索引
alter table 表名 add 索引类型 索引名称(字段名称);
1 2 |
alter table t11 add unique name_unique(username);#uni |
删除唯一索引
alter table t11 drop index 索引名;
1 2 |
alter table t11 drop index name_unique; |
添加普通索引
1 2 3 |
alter table t11 add index index_name(username);#mul alter table t11 drop index index_name; |
查看表中的索引
1 2 |
show indexes from t11; |
在MySQL中,主要有四类索引:
1. 主键索引(PRIMARY KEY)
1. 唯一索引(UNIQUE)
1. 常规索引(INDEX)
1. 全文索引(FULLTEXT)