我建了一个带有序号的表,怎么实现批量添加呢,初学者,要详细地代码案例,谢谢

解决方案 »

  1.   

    declare @tab  table (iid int )
    insert into @tab
    select row_number() over(order by a.object_id) from sys.objects a,sys.objects b
    select * from @tab
      

  2.   

    insert into tb(字段) values(..)
      

  3.   

    批量添加可以从客户端直接输入经 union 的一系列数据,比如:
    insert into tb select 1,'aa'
    unoin all select 2,'bb'
    union all select 3,'cc'
    union all select 4,'dd'
    也可以从其他表中通过查询获得,比如:
    insert into tb select * from othertb where yourcn
    你想要批量添加什么?
      

  4.   


    --假设你的序号列是 tid,还有其它两列aa,bb,插入的时候
    insert into tb(aa,bb)
    select 'a1','b1' union all
    select 'a2','b2' union all
    select 'a3','b4' union all
    select 'a5','b4'
    --如果字段属性是int,money等这些,可以不用单引号'' 
      

  5.   


    --同理,如果你想把其它表的资料转移到你创建的这个表中,插入的时候要指定列,避开自增列
    insert into tb(aa,bb)
    select aa,bb from tbold