码迷,mamicode.com
首页 > 数据库 > 详细

SQL -- insert

时间:2015-08-09 15:23:22      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

SQL – insert

SQL – insert

desc user1;

| id       | int(11)     | NO   |     | NULL    |       |
| username | varchar(20) | NO   |     | NULL    |       |
insert into user1 (id, username) values (1, ‘user1‘);
select * from user1;
insert into user1 (id, username) values (2, ‘user2‘), (3, ‘user3‘);
select * from user1;

将一个表中查询到的结果插入到另一个表中

truncate table user1;

insert into user1 (id, username) values (1, ‘test1‘);
insert into user1 (id, username) values (2, ‘test2‘);
insert into user1 (id, username) values (3, ‘test3‘);
insert into user1 (id, username) values (4, ‘test4‘);

select * from user1;

create table tmp (
test_id smallint,
test_name varchar(10)
);
insert into tmp (test_id, test_name) select id, username from user1 where id > 2;  # 注意不需要加 values

select * from tmp;
|       3 | test3     |
|       4 | test4     |
drop table tmp;

SQL -- insert

标签:

原文地址:http://www.cnblogs.com/sunznx/p/4715049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!