In SQL, 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.
There are two types of temporary tables: local and global. Here are the differences between them:
Scope is the primary distinction between local and global temporary tables. While global temporary tables are visible during all sessions, local temporary tables are only viewable within the current session.
Name: The names of local temporary tables begin with a single pound symbol (#), while those of global temporary tables begin with two pound signs (##).
The CREATE TABLE statement creates local temporary tables for the current session; the CREATE TABLE statement with a double pound sign (##) prefix creates global temporary tables.
Local temporary tables are automatically removed at the conclusion of the current session, whereas global temporary tables are automatically deleted after the final session that made use of the table closes.
Global temporary tables are accessible to all users who have authorization to access them, whereas local temporary tables inherit permissions from the user who created them.
In summary, local temporary tables are created and destroyed within the current session and are only visible to the current user, while global temporary tables can be accessed across sessions and are visible to all users who have permissions to access them.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
In SQL, 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.
There are two types of temporary tables: local and global. Here are the differences between them:
In summary, local temporary tables are created and destroyed within the current session and are only visible to the current user, while global temporary tables can be accessed across sessions and are visible to all users who have permissions to access them.
Difference between local temporary tables and global temporary tables are as follows: