在一个存储过程中为什么这样写不行?因为我不想用太多个临时表,所以要删除了再插入数据,这样不行吗?if(object_id('tempdb..#t') is not null)
  drop table #t
select * into #t from t
if(object_id('tempdb..#t') is not null)
  drop table #t
select * into #t from t提示:数据库中已存在名为 '#t' 的对象。已经删除了为什么还提示已存在名为 '#t' 的对象。

解决方案 »

  1.   


    if(object_id('tempdb..#t') is not null) 
    drop table #t 
    select * into #t from a 
    go --注意这里
    if(object_id('tempdb..#t') is not null) 
    drop table #t 
    select * into #t from a 
      

  2.   

    to pt1314917 
    你的这个头像不好看,还不如原来的呢
      

  3.   


    if(object_id('tempdb..#t') is not null) 
      drop table #t  -------------------------->>没有执行
    select * into #t from t ------------------->>所以会提示#t已经存在
    if(object_id('tempdb..#t') is not null) 
      drop table #t 
    select * into #t from t 临时表只有当你的这次连接结束的时候才会删除掉。lz可以试试,你把你的这次连接断开,然后再连接,临时表就不存在了。
    但是你的并没有断开连接
      

  4.   

    没有断开,我不是手动drop table #t 了吗
      

  5.   

    GO
    用信号通知 Microsoft® SQL Server™ 实用工具一批 Transact-SQL 语句的结束。
      

  6.   

    drop table 临时表,后面需要加go,才能再创建这个临时表
    而你的存储过程里不能用go联机文档有文:
    如果在单个存储过程或批处理中创建了多个临时表,则它们必须有不同的名称。
      

  7.   

    純粹是SQL Server语法分析器的BUG...
      

  8.   

    純粹是SQL Server语法分析器的BUG...
      

  9.   

    和语法有什么关系.是sql server处理机制的问题
      

  10.   


    谈不上啥处理机制问题吧,语句分析都通不过了。
    你在Analyzer上Ctrl+F5分析一下看能否通过??