假定原表为A,复制指定表为 B:
if object_id('B') is null
    select * into B from A where ...
else
    insert into B select * from A where ...

解决方案 »

  1.   

    if not exists (select 1 from sysobjects where name='另一个表' and xtype='u')
    begin
    create 另一个表(....)
    end
    go
    insert 另一个表(col1,col2,...) select 对应的列 from tablename
      

  2.   

    insert B select top 10000 * from A
    A為原來得表,B為備份表
      

  3.   

    if object_id('Table_SJBF_Data') is null select * into Table_SJBF_Data from Table_Subscribe_User 
    else insert into Table_SJBF_Data select * from Table_Subscribe_User当表存在时出现如下错误
    服务器: 消息 8101,级别 16,状态 1,行 2
    仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'Table_SJBF_Data' 中为标识列指定显式值。
      

  4.   

    IF EXISTS(SELECT name 
      FROM   sysobjects 
      WHERE  name = N'B'
      AND   type = 'U')
    create table B()insert B select top 10000 * from A
    A為原來得表,B為備份表
      

  5.   

    又錯了,不好意思是
    IF  not EXISTS(SELECT name 
      FROM   sysobjects 
      WHERE  name = N'B'
      AND   type = 'U')  
    create table B()insert B select top 10000 * from A
    A為原來得表,B為備份表
      

  6.   

    服务器: 消息 8101,级别 16,状态 1,行 2
    仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'Table_SJBF_Data' 中为标识列指定显式值。我想知道这个错误是怎么回事?应该怎么解决呢??insert B select top 10000 * from A
    只要是这样的语句,就会出现上面的错误