HEELPBOOK - SQL Server - If temp table exists - Drop it! ######################## You've created a temp table in a stored procedure and now you are testing it which involves dropping a temp table manually if you are not executing the stored procedure in it's entirety (common if you are testing chunks of it). So here's the easy solution. We need to check if the temp table exists within the TempDB database and if it does, we need to drop it. Place the following at the top of your procedure, obviously before creating the temp table =] Now everytime it runs it will drop the table and then recreate it, no more manually dropping the temp table! IF OBJECT_ID('tempdb..#Temp') IS NOT NULL DROP TABLE #Temp Replace #Temp with the name of your temp table. Hope this helps! ############ ARTICLE INFO ############# Article Month: May Article Date: 10/05/2012 Permalink: http://heelpbook.altervista.org/2012/sql-server-if-temp-table-exists-drop-it/ Source: http://lordfu.wordpress.com/2010/07/29/if-temp-table-exists-drop-it/ Language: English View more articles on: http://www.heelpbook.net/ Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832 Follow us on Twitter: https://twitter.com/#!/HeelpBook Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook Follow us on Delicious: http://delicious.com/heelpbook