MYSQL数据插入的简单使用

先建一张基础表进行测试

create table user
(
	id INT NOT null auto_increment,
	name CHAR(10) not NULL DEFAULT'',
	age INT not null DEFAULT 0,
	PRIMARY KEY(id)
);

1.id使用默认自增的方式添加记录

insert into user(name,age) values('xixi',12);
#一次性插入多条记录
insert into user(name,age) VALUES('xixi',20),('haha',30);

2.为所有字段插入数据

insert into user(id,name,age) values(4,'zhangsan',20);
#一次性插入多条记录
insert into user(id,name,age) values(5,'lisi',30),(6,'wangwu',40);

3.还可以使用INSERT INTO…FROM 语句将查询结果插入到表中

当然这条命令在数据量大的时候别随便使用!!
因用了Insert into select语句,同事被开除了!

create table user2(
	id int not null auto_increment,
	name char(10) not null DEFAULT '',
	age INT,
	PRIMARY key(id)
)
INSERT INTO user2(id,name,age) SELECT id,name,age from user;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值