怎么样用sql 语句 复制一张一模一样的表 而且  里面的数据也要存在  

解决方案 »

  1.   

    SELECT * INTO NEWTB FROM TB
      

  2.   

    ---要看你新表存不在存在
    如果存在
    select * into tb from ta
    如果不存在
    insert into tb select * from ta
      

  3.   

    select into '目标表' from '原表'
      

  4.   

    n-m條記錄
    1.
    select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入
    set rowcount n
    select * from 表变量 order by columnname desc
    2.
    select top n * from 
    (select top m * from tablename order by columnname) a
    order by columnname desc
    3.
    如果tablename里没有其他identity列,那么:
    select identity(int) id0,* into #temp from tablename取n到m条的语句为:
    select * from #temp where id0 >=n and id0 <= m如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开要先执行:
    exec sp_dboption 你的DB名字,'select into/bulkcopy',true
    4.
    如果表里有identity属性,那么简单:
    select * from tablename where identitycol between n and m 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ws_hgo/archive/2008/12/17/3541083.aspx
      

  5.   

    如果存在
    insert into tb select * from ta
    如果不存在
    select * into tb from ta
      

  6.   

    如果目标表存在
    insert into tb select * from ta
    如果目标表不存在
    select * into tb from ta
      

  7.   

    说反了,如果表存在的话,用insert into tb select * from ta
    如果不存在,用select * into tb from ta
      

  8.   

    SELECT * INTO NEWTB FROM TB