Friday, May 15, 2020

What is the difference between a Local and a Global temporary table?

What is the difference between a Local and a Global temporary table?

Temporary tables are used to allow short term use of data in SQL Server. They are of 2 types:

Local
- Only available to the current Db connection for current user and are cleared when connection is closed.
- Multiple users can’t share a local temporary table.

Global
- Available to any connection once created. They are cleared when the last connection is closed.
- Can be shared by multiple user sessions.

What is the difference between a Local and a Global temporary table?

A local temporary table lives until the connection is valid or until the duration of a compound statement.

A global temporary table is permanently present in the database. However, the rows of the table are present until the connection is existent. Once the connection is closed, the data in the global temporary table disappears. However, the table definition remains with the database for access when database is opened next time.

No comments: