• Firstly, because temp tables are in tempDB, and unless you are in that database, sys.tables refers to your user database's tables, not TempDB.

    Secondly, because the name in the system catalog is not #Temp. It'll be something like #Temp________________________________8FE34A. Hence your first one won't work.

    The second risks false positives. If another connection has a temp table named #TempAccount, your exists would pick it up, return true and then the

    drop will fail because there's no temp table #Temp on your connection. Again, that's if run while the connection is using TempDB.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass