日期:2014-05-18  浏览次数:20542 次

两个表数据合并的问题!
有两个表分别为A表与B表,两表的字段一样,
现A表的数据为:

SQL code
姓名  成绩

王二  82


现B表的数据为:
SQL code
姓名  成绩

王三  67


问题:想把B表的数据追加到A表,结果为:
SQL code
姓名  成绩

王二  82
王三  67


请问语句怎么写?什么方案效率最高呢?

------解决方案--------------------
SQL code
INSERT A SELECT * FROM B

------解决方案--------------------
insert into a select * from b
------解决方案--------------------


if object_id('tempdb..tb1')>0
drop table tb1
create table tb1
(
 tname varchar(20),
 score int
)
insert into tb1(tname,score)
select '王二',82


if object_id('tempdb..tb2')>0
drop table tb2
create table tb2
(
 tname varchar(20),
 score int
)
insert into tb2(tname,score)

select '王三',67



insert into tb1
select * from tb2
------解决方案--------------------
SQL code
insert into a select * from b