我在单个脚本中多次创建/删除临时表
IF OBJECT_ID('tempdb..#uDims') IS NOT NULL
DROP TABLE #uDims
select * into #uDims from table1
.... do something else
IF OBJECT_ID('tempdb..#uDims') IS NOT NULL
DROP TABLE #uDims
select * into #uDims from table2 -- >> I get error here
.... do something else
IF OBJECT_ID('tempdb..#uDims') IS NOT NULL
DROP TABLE #uDims
select * into #uDims from table3 -- >> and here
.... do something else
我尝试运行这个脚本时,出现了以下错误:
There is already an object named '#uDims' in the database.
在第二个和第三个“select into…”语句中出现了编译时错误。如果我逐个运行脚本的每个部分,一切都会正常工作。
有许多解决此问题的方法,但我想知道为什么SSMS对此感到不满。