测试数据
create table tb(c1 int)
insert tb select 1
union all select 2
union all select 3
union all select 4
union all select 5create table #t1(c1 int)create table #t2(c1 int)我现在需要的是想查询出ta 的数据,然后一次性插入到#t1,#t2两个临时表中
请问怎么做呢

解决方案 »

  1.   

    insert #t1 select * from tb
      

  2.   

    楼上说的只是把select出来的结果插入到一张表里边去
    我现在的目的是要把select的结果一次性插入到两张表中去
      

  3.   

    在其中一张表上建立个触发器:
    create trigger tri_t1
    for insert
    on t1
    as
    insert t2 select * from inserted然后:
    insert #t1 select * from tb
      

  4.   

    用事务 
    insert #t1 select * from tb
    insert #t2 select * from tb然后提交
      

  5.   

    insert #t1 select * from tb
    insert #t2 select * from tb直接执行这两句话,就是一次把数据插入到两个表里。
      

  6.   

    就是我只select出来一次
    而不是象楼上的需要select两次出来
      

  7.   

    用一句SQL实现的话oracle可以,不知道T-SQL怎么实现?关注!
      

  8.   

    我也是想找出答案
    不知道行不
    如果用两个select的话,速度句要慢了
    所以想一次性插入到两个表里
    大家帮忙想想看,有没有办法
      

  9.   

    触发器
    create trigger tri_t1
    for insert
    on t1
    as
    insert t2 select * from inserted然后:
    insert #t1 select * from tb
      

  10.   

    好的
    谢谢大家了
    看来SQL里没有我想要的这种办法