表[A]:ID、TempID、......
表[B]:ID、......两表的结构差不多,不同的是各自有自己的 int标识步长1为主键 ID,其表[A]多一个int类型的TempID字段现在 Insert into [B](......) Select ...... From [A]问题是 [A]:TempID怎么 对应更新 = [B]:ID

解决方案 »

  1.   

    insert into b(id,...) select tempid,...from a
      

  2.   

    方法很多,介绍一种最简单的方法
    A表有(列1,列2,列3)
    B表有(id列,列2,列3)
    declare @ta table(id int identity(1,1),列2,列3)
    insert @ta
    select 列2,列3 from A表
    insert B表
    select * from @ta
      

  3.   

    方法2:
    select id=identity(int,1,1),列2,列3 into #
    from A表
    insert B表
    select * from #--通过生成临时表插入数据
      

  4.   

    如果B表有自增列打自增列关了就行了
    SET IDENTITY_INSERT off--关插入数据
    SET IDENTITY_INSERT on--再打开