The Temp table is stored in tempdb until the connection is deleted (or in the case of global temporary tables, when the last connection to it is deleted). You can also (and this is good practice) manually drop the table when you finish using it with the drop-down table instruction.
No, others cannot see your temporary tables if they are local temporary tables (they can see and use global temp tables). Several people can run commands that use the same temp table name, but they will not overlap in the local temp table and therefore you can have a table named #test and therefore 10,000 other users, but each of them has its own structure and data.
You do not want to look for temporary tables at all in tempdb. You can check for availability, but this is the only time I have referenced tempdb directly. Just use the temp table name. Example below check for availability
IF OBJECT_ID('TempDB.dbo.#DuplicateAssignments') IS NOT NULL BEGIN DROP TABLE #DuplicateAssignments END
You name the temporary tables, preceded by the name # (for local tables â you would use 999.9% of the time) and ## for global temporary tables, and then the rest of the name you want.
Hlgem
source share