--我连续执行了N次都没有错if not exists(select 1 from sysobjects where name='tb' and xtype='U')
  create table tb(a int)

解决方案 »

  1.   

    if not exists(select 1 from sysobjects where name= 'table_name' and xtype='U')
      create table  table_name(……)
      

  2.   

    --或者:
    if object_id('表名') is null
    create table 表名(a int)
      

  3.   

    --我连续执行了N次都没有错if not exists(select 1 from sysobjects where name='tb' and xtype='U')
      create table tb(a int)再分析器里面是不会出错的,不过再bcb里就要出错,不知道怎么会使
      

  4.   

    sql自己产生的脚本,用于删除表a,你可以参考一下
    if exists (select * from dbo.sysobjects where id = object_id(N'[a]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [a]
    将你的语句改为:
    if not exists (select * from dbo.sysobjects where id = object_id(N'[a]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
       create table  table_name
      

  5.   

    sql自己产生的脚本,用于删除表a,你可以参考一下
    if exists (select * from dbo.sysobjects where id = object_id(N'[a]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [a]
    将你的语句改为:
    if not exists (select * from dbo.sysobjects where id = object_id(N'[a]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
       create table  table_name
    这个代码我业写过的,执行多次就不行了
      

  6.   

    加上try,catch就可以了
    奶奶的,