爲什麼沒有任何問題此代碼的工作:差異
drop table t1
select * into t1 from master..spt_values
drop table t1
select * into t1 from master..spt_values
輸出
Msg 3701, Level 11, State 5, Line 1
Cannot drop the table 't1', because it does not exist or you do not have permission.
(2508 row(s) affected)
(2508 row(s) affected)
但是這個代碼不:
drop table #t1
select * into #t1 from master..spt_values
drop table #t1
select * into #t1 from master..spt_values
輸出
Msg 2714, Level 16, State 1, Line 4
There is already an object named '#t1' in the database.
此代碼中表和臨時表之間有什麼區別?
好問題。爲了更好地說明你的觀點[這個SQLFiddle](http://sqlfiddle.com/#!3/d41d8/5748)不起作用,但用普通表替換 – RichardTheKiwi
[對行爲的解釋在這裏](http: //sqlblog.com/blogs/michael_zilberstein/archive/2008/08/28/Name-resolution-in-SQL-Server.aspx)對於't1'語句可以延遲編譯,但是對於'#' t1' –
正如一邊注意「[DROP TABLE和CREATE TABLE不應該在同一批次的同一張表上執行,否則可能會發生意外錯誤。](http://msdn.microsoft.com/zh-cn/庫/ ms173790.aspx)「 –