Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duration of data in a Global Temporary table?

Tags:

sql

oracle

Can someone please tell me: how long will data be there in a Global Temporary table?

like image 521
Avi Avatar asked Feb 16 '11 14:02

Avi


People also ask

How long do temp tables persist?

Temporary tables can have a Time Travel retention period of 1 day; however, a temporary table is purged once the session (in which the table was created) ends so the actual retention period is for 24 hours or the remainder of the session, whichever is shorter.

How long do temporary tables last in SQL Server?

Local temporary tables are deleted after the user disconnects from the instance of SQL Server. Global temporary tables are visible to any user and any connection after they are created, and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.

What is a global temporary table?

Global Temporary Tables (GTTs) are the Oracle tables, having data type as private; such that data inserted by a session can be accessed by that session only. The session-specific rows in a GTT can be preserved for the entire session, as AI report tables are created using ON COMMIT PRESERVE ROWS clause.

What is the difference between temp table and global temp table?

There are two varieties of temp tables. Local temp tables are only accessible from their creation context, such as the connection. Global temp tables are accessible from other connection contexts. Both local and global temp tables reside in the tempdb database.


2 Answers

They can be SESSION based (data survives a commit but not a disconnect/reconnect). They can also be TRANSACTION based (data disappears after a commit).

This creates a transaction based temp table:

create global temporary table temp_table_transaction on commit delete rows ...

This creates a session based temp table:

create global temporary table temp_table_transaction on commit preserve rows ...
like image 66
Gabriel Magana Avatar answered Oct 01 '22 23:10

Gabriel Magana


When you create a temporary table you have two options for data persistence:

  • ON COMMIT DELETE ROWS (default) and
  • ON COMMIT PRESERVE ROWS

If you don't specify a persistence clause, or specify ON COMMIT DELETE ROWS, the data in the table will be transaction-specific (it will be deleted upon commit or rollback).

If you specify ON COMMIT PRESERVE ROWS, the data will stay until the end of your session.

like image 37
Vincent Malgrat Avatar answered Oct 01 '22 23:10

Vincent Malgrat