create table test1(a1 int,a2 int)
insert into test1 select 1,2create table test2(a1 int,a2 int,a3 char(4),a4 char(2))
insert into test2 select 1,3,1,1test2表 ,希望得到效果:
a1    a2     a3      a4
1      3     1       1
1      2    null    null

解决方案 »

  1.   

    select * from test2
    union all
    select *,null,null from test1
      

  2.   

    insert into test2
    select *,null,null from test1select * from test2
      

  3.   

    insert into test2
    select *,null,null from test1
      

  4.   

    你的意思是 每个字段都要写上去?
    null也要写上去?
      

  5.   

    恩,因为他们字段数目不一致,你需要指定相同的字段数目insert into test2(a1,a2)
    select *  from test1select * from test2
      

  6.   

    INSERT test2 (a1,a2) SELECT * FROM test1
      

  7.   

    create table test1(a1 int,a2 int)
    insert into test1 select 1,2create table test2(a1 int,a2 int,a3 char(4),a4 char(2))
    insert into test2 select 1,3,1,1select m.* from test2 m 
    union all 
    select n.* , null , null from test1 n drop table test1 , test2/*
    a1          a2          a3   a4   
    ----------- ----------- ---- ---- 
    1           3           1    1 
    1           2           NULL NULL(所影响的行数为 2 行)*/