如:数据库A中的A1表
结构:
id    name   tel数据库B中的B1表结构:
id    name
如何把A1中的数据插入到B1中(要求是id不相同的)

解决方案 »

  1.   

    insert into b
    select id,name
    from a
    where not exists (select 1 from b where id = a.id)
      

  2.   

    insert into B库.dbo.B1
     select id,name from A库.dbo.A1 a
        where not exists(select 1 from B库.dbo.B1 where id=a.id)
      

  3.   

    insert into B.b
    select id,name
    from A.a
    where not exists (select 1 from B.b where id = A.a.id)
      

  4.   

    insert into B..b
    select id,name
    from A..a t
    where not exists (select 1 from b where id = t.id)不同数据库
      

  5.   

    insert
     into B.dbo.B
    select
     id,name from A.dbo.A a
    where
     not exists(select 1 from B.dbo.B where id=a.id)
      

  6.   

    仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 B.dbo.B
    中为标识列指定显式值。
      

  7.   


    set identity_insert B..b oninsert into B..b(id,name)
    select id,name
    from A..a t
    where not exists (select 1 from b where id = t.id)set identity_insert B..b off