Wayne Sheffield offers a clinic on temp tables:
I was recently reviewing a newly created T-SQL stored procedure. This procedure was verifying temporary table existence with the following code:
2 IF exists (select * from tempdb..sysobjects where name like ‘#fg%’)DROP TABLE #fgSeeing this takes me back to one of my favorite presentations, where I compare Temporary Tables and Table Variables. In this, I go over several of the methods that I have seen for how code found on the internet actually does this taskā¦ and I show why they are all doing it wrong.
Read on to understand why this isn’t the correct answer.