数据库的简单操作02
一次插多条
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 要修改的字段名 改后的字段名varchar(20) not null;
modify只能修改字段的属性不能修改字段名称 alter table t11 change name username varchar(10);
添加字段
alter table 表名 add 字段名 varchar(20) not null default 'aa';
alter table t11 add sex enum('男','女');
删除字段
alter table 表名 drop 字段名;alter table t11 drop sex;
修改表名
rename table 原名 to 新名;rename table t11 to t121;
Alter table 表的旧名称 rename as 表的新名称; alter table t121 rename as t11;
删除主键索引 (先去除自增再删除)
alter table t11 change id id int(8) unsigned;
alter table t11 drop primary key;
添加索引
alter table 表名 add 索引类型 索引名称(字段名称);alter table t11 add unique name_unique(username);#uni
删除唯一索引
alter table t11 drop index 索引名;alter table t11 drop index name_unique;
添加普通索引
alter table t11 add index index_name(username);#mul
alter table t11 drop index index_name;
查看表中的索引
show indexes from t11;
在MySQL中,主要有四类索引: 1. 主键索引(PRIMARY KEY) 1. 唯一索引(UNIQUE) 1. 常规索引(INDEX) 1. 全文索引(FULLTEXT) 本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。