2010-07-21 65 views
1

我需要从几个表中将所有相同字段名的数据插入到一个临时表中,我知道我可以使用游标/循环来做到这一点,我想知道有没有更快的方式做到这一点。从8表中选择数据到一个临时表

从表1,表2,表3中选择#temptable。

回答

3
select * into #temptable from table1 

insert into #temptable select * from table2 
insert into #temptable select * from table3 

第一个查询在插入时创建临时表,其余的只是继续添加数据。