欢迎光临
感谢一路有你

数据库的简单操作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)

赞(0) 打赏
未经允许不得转载:王明昌博客 » 数据库的简单操作02
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏