我在存储过程中使用  drop  table  T  ,通常由于多人同时调用这个存储过程导致出错,请问sql怎么判别表是否存在,再删除,谢谢

解决方案 »

  1.   


    if exists (select * from dbo.sysobjects where id = object_id(N'[tb]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [tb]
      

  2.   

    尽量用临时表,这样在并发时才不容易产生错误。create table #temp
      

  3.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[tb]')
      

  4.   

    if object_id('T') is not null
    drop table T
      

  5.   

    你们误会了巴, 我工作里就遇到 drop 的情况, 当然我用的是表变量。。if object_id('MyTbl') is not null
        drop table MyTbl
      

  6.   


    select * from sysobjects where xtype='U' and name='[TableName]'