我正在使用sql2000,我想自動將#temp表放入sproc實例或查詢窗口中。這比測試更適合生產。有沒有辦法獲得當前會話或sproc實例或查詢實例,並使用它來刪除該實例中的#temp表。我不想在其他實例中刪除#temp表。如何獲取當前的sproc會話ID並刪除該sproc實例中存在的臨時表?
我發現用這個code另一個堆棧溢出問題:
declare @sql nvarchar(max)
select @sql = isnull(@sql+';', '') +
'drop table ' + quotename(name) from tempdb..sysobjects
where name like '#%' exec (@sql)
我只想檢測當前會話或實例只#tmp表。我也將需要在sql2008中做到這一點。 thx
謝謝。
臨時表自動當它們超出範圍時就會下降。看到http://stackoverflow.com/questions/892351/sql-server-2005-and-temporary-table-scope –
米奇,我正在查詢窗口中進行測試。它們不會在您正在測試的查詢窗口中超出範圍。所以我想放入一些代碼,並刪除所有#temp表和walla ...沒有更多的臨時表。我不想每次都要打開一個新的查詢會話b/c我很懶。 – RetroCoder
然後我懷疑你正在使用臨時表格......你應該在不再使用臨時表格的時候刪除它。 –