I’m using sql2000 and I want to automatically drop a #temp table in a sproc instance or in a query window. This is more for testing purposes than production. Is there a way to get the current session or sproc instance or even a query instance, and use that to delete only #temp tables in that instance. I don’t want to drop #temp tables in other instances.
I noticed another Stack Overflow question used this code:
declare @sql nvarchar(max)
select @sql = isnull(@sql+';', '') +
'drop table ' + quotename(name) from tempdb..sysobjects
where name like '#%' exec (@sql)
I just want to detect only #tmp tables in current session or instance. I also will need to do this in sql2008. thx
Thanks.
Your current SPID, again this works on 2005 and up I have not tested it on a 2000 instance
shows what you are doing in that spid workins in 2005 and up not sure about the 2000 version
Find spids and kernel threads before execute the test take a screen shot
Run the SQL again once you start your testing
reference this site http://support.microsoft.com/kb/117559
To drop your temp table if you know the names you can expand on this to get the desired result