The comments cover the most frequent methods, which for completeness are:
- Right click in query window and go to
Connection > Change Connection
, causing the session to refresh, hence dropping the temp tables - Copy SQL to a new window does the same
When testing, I frequently have block commented drop commands at the top of the testing window that you can select and run (Hit F5), like so:
/*
DROP TABLE #TEMP1
DROP TABLE #TEMP2
*/
SELECT TOP 1 *
INTO #TEMP1
FROM Users
SELECT TOP 1 *
INTO #TEMP2
FROM Users
So you just simply highlight the lines between the comments and run the selected statements.
Usually if I'm happy the entire query will run, I'll just have the DROP
statements at the end, so I can re-run over and over, unless of course you want to interrogate the #TEMP
tables.