存储过程如何删除临时表?没有参数,直接判断删除

解决方案 »

  1.   


    if exists (select 1 from sysobjects where xtype = 'u' and id = object_id('temp..#tb'))
        drop table #tb
    go
      

  2.   

    drop table tb --直接删除表delete from tb  --删除表所有数据,有日志truncate table tb  --删除表所有数据,没有日志
      

  3.   


    Create table #tb
    (id int,
     name nvarchar(20))
    GO--1--
    if object_id('#tb') is  null 
    drop table #tb
    GO
    --2--
    if not exists (select 1 from sysobjects where xtype = 'u' and id = object_id('temp..#tb'))
        drop table #tb
    GO--1-- 不加not null才可以删除 (判断是否存在表不是not null吗?)
    --2--要加not exists 才可以删除 ,不合逻辑我SQL2005有问题吗
      

  4.   

    if object_id('#tb') is  null 
        drop table #tb
    条件是如果#tb表是空,也就是不存在,你删个屁啊