Is there a way to get a list of all current temporary tables in SQL Server?
Quickly get a list of all current temporary tables in your SQL Server session by:
This produces all current session-specific temporary tables. Remember, SQL Server appends a strange suffix to your temp table names.
Temp table details
To focus the search on user-created tables and dodge system objects, throw in a type
filter:
Getting nostalgic with SQL Server 2000? Its older sysobjects
table has got you covered:
Play according to the rules, you’d need adequate permissions to query these metadata tables.
Targeted Search
Session-specific versus global temporary tables, how to tell them apart? The cues lie in their naming conventions:
Confirm the existence of an elusive temporary table with the OBJECT_ID
function. It's like checking if the bogeyman is under your bed:
Tracking Performance
For slow queries involving temporary tables, strap on the SQL Profiler and step into the shoes of a query detective.
As a developer, you might find it beneficial to maintain a timeline of procedural events. A dedicated log table can come in handy:
Compatibility Quirks
Uh-oh, the SQL Server version is acting up. What's a coder to do? Adjust. Always adjust.
Mind your syntax and object names. Version changes can be tricky.
##%'; -- Global tents, the bigger crowd SELECT [name] FROM tempdb.sys.tables WHERE [name] LIKE '#%'; -- Local tents, humbler crowd
Was this article helpful?