• There are thee types of 'temp' tables, all stored in the tempDB database.

    Global Temp Tables.

    Created by CREATE TABLE ##MyTempTable AS ...

    They are visible to all sessions. If not explicitly dropped, they are removed when all connections that reference them have disconnected from the server.

    Visible in tempDB with the same name as they were created (##MyTempTable )

    Local Temporary tables

    Created by CREATE TABLE #MyTempTable AS ...

    These are visible only to the connection that created them. If not explicity droped, they are dropped as soon as the connection that created them is closed, or the stored proc that created them completes (whichever occurs first)

    Visible in tempDB with a name like #MyTempTable____________________________________________________________________________000000000002

    Table variables

    Created by DECLARE @myTableVar TABLE ...

    Visible only in the scope they were created in. Dropped as soon as they go out of scope. Cannot be explicitly dropped.

    Visible in tempdb with names like #0DAF0CB0

    Does that clear things up?

    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