Search⌘ K

Temporary Tables

Explore the use of temporary tables in T-SQL programming, including how to create and manage local and global temporary tables. Understand their scope within sessions, syntax differences, usage scenarios, and storage in the tempdb system database to handle intermediate data in complex queries.

Besides table variables, there are temporary tables we can utilize in our complex queries to hold intermediate data. Unlike table variables that exist only within the scope of a batch, temporary tables are accessible throughout the whole session when there’s a connection to the MS SQL Server. Temporary tables can be either local or global.

Temporary table types

There are two types of temporary tables in MS SQL Server.

Local temporary tables

Local temporary tables are accessible only from the session they are created in. Users or applications connected to the MS SQL Server are ...