A temporary table stores data that exists only during a transaction or session. This topic describes how to create a global temporary table (GTT) in OceanBase Database.
What is a GTT?
A GTT stores data for a specific period of time, which can be the lifecycle of a transaction or session.
A GTT can be visible to all sessions. However, data in the GTT is private to a session, and the session can access and modify only its own data.
For example, a course schedule application enables a college student to create semester schedules. Each row in the GTT represents a course schedule. During the session, the course schedule data is private to the session. When the student confirms a course schedule, the application moves the row of the selected schedule to a normal table. When the session ends, the database automatically deletes data in the GTT.
Create a GTT
You can execute the CREATE GLOBAL TEMPORARY TABLE statement to create a GTT. The ON COMMIT clause specifies whether to create a transaction- or session-level temporary table.
You can create an index for a GTT. Data in the GTT is temporary data private to a session.
Example: Create a transaction-level temporary table.
obclient> CREATE GLOBAL TEMPORARY TABLE tbl1(col1 INT) ON COMMIT DELETE ROWS;
Query OK, 0 rows affected