有如下三个表:表A:字段1, 字段2, 字段3表B:字段1, 字段2, 字段3表C:字段1, 字段2, 字段3现在想复制A表的字段1,B表的字段2,C表的字段3到表4中去。不需要表中的数据。用SQL语句应如何实现呢?

解决方案 »

  1.   

    select a.col1, b.col2, c.col3
    into table4
    from tableA a, tableB b, tableC c
    where 1 = 0
      

  2.   

    如果表存在的话,那就用
    insert into 表4 select a.字段1,b.字段2,c.字段3 from 表A a,表B b,表C c where 条件如果表4不存在
    select a.字段1,b.字段2,c.字段3 into 表4 from 表A a,表B b,表C c where 条件
      

  3.   

    如果表存在的话,那就用insert into 表4 select a.字段1,b.字段2,c.字段3 from 表A a,表B b,表C c where 条件
    ------------------------------------------------------------------------------->好像不行啊,我的条件写的是:1<>1表4中没有增加所需的字段。
      

  4.   

    1<>1
    ----------条件是什么意思?
      

  5.   

    1<>1
    ----------条件是什么意思?
    --------------------相当于1=0
      

  6.   

    select
        *
    into 表5
    from
        表4 m
    left join
        (select a.字段1,b.字段2,c.字段3 from 表A a,表B b,表C c where 1<>1) n
    on
        1=1drop table 表4exec sp_rename '表5','表4'
      

  7.   

    libin_ftsafe(子陌红尘)
    ---------------------->如果表中有重复的字段该怎么办呢?