相关疑难解决方法(0)

数据库中已经有一个名为"#columntable"的对象

我正在尝试以下查询

   if exists (select 1  from emp where eid = 6)     
     begin
        if object_id('tempdb..#columntable') is not null 
          begin 
             drop table #columntable                         
          end                     
        create table #columntable (oldcolumns varchar(100))   
     end
  else
     begin
        if object_id('tempdb..#columntable') is not null 
          begin 
             drop table #columntable            
          end     


    create table #columntable (newcolumns varchar(100))   
 end
Run Code Online (Sandbox Code Playgroud)

但是我收到了错误

Msg 2714, Level 16, State 1, Line 8
There is already an object named '#columntable' in the database.
Run Code Online (Sandbox Code Playgroud)

谁有人建议为什么?如果我不写else部分,相同的查询工作正常.

sql t-sql sql-server-2005

8
推荐指数
2
解决办法
4万
查看次数

标签 统计

sql ×1

sql-server-2005 ×1

t-sql ×1