t1 
a int 
b int 
c intt2 
a int 
b int t1和t2表的a 和 b 都是联合主键
t1表中包含t2中所有中的数据,
怎样才能把t1中有在t2中没有的数据插入T2

解决方案 »

  1.   

    --试一下
    INSERT T2
    SELECT *
    FROM T1 A
    WHERE NOT EXISTS
    (SELECT 1 FROM T2 WHERE A=A.a AND B=A.b)
      

  2.   

    insert t2 select T.a,T.b from t1 T where not exists (select 1 from t2 where T.a=a and T.b=b)
      

  3.   

    create table t1 
    (
    a int, 
    b int, 
    c int
    )
    insert t1
    select 1,2,3 union all
    select 2,2,3 union all
    select 3,2,3 
    select * from t1create table t2 
    (
    a int,
    b int

    insert t2
    select 1,2 union all
    select 3,2
    select * from t2begin traninsert t2(a,b)
    select A.a,A.b from t1 A left join t2 B on A.a=B.a and A.b=B.b where B.a is null
    select * from t2rollback trandrop table t1,t2