0% found this document useful (0 votes)
37 views1 page

Global Temporary Tables: Chapter 1: Creating

Global temporary tables allow data to be partitioned for each connection like local temporary tables, but the table schema is stored in the system catalog like permanent tables. The data in a global temporary table is only visible to the connection that inserts it. The commit action specifies whether data is deleted or preserved on commit. ON COMMIT DELETE ROWS is the default and deletes data on commit, while ON COMMIT PRESERVE ROWS commits changes instead of deleting data.

Uploaded by

Nishki Gejmer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views1 page

Global Temporary Tables: Chapter 1: Creating

Global temporary tables allow data to be partitioned for each connection like local temporary tables, but the table schema is stored in the system catalog like permanent tables. The data in a global temporary table is only visible to the connection that inserts it. The commit action specifies whether data is deleted or preserved on commit. ON COMMIT DELETE ROWS is the default and deletes data on commit, while ON COMMIT PRESERVE ROWS commits changes instead of deleting data.

Uploaded by

Nishki Gejmer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

36 Chapter 1: Creating

Tip: In SQL Anywhere 9 you can call a procedure in the SELECT FROM
clause. This means you can treat a procedure call just like a table, and join it to
other tables.

1.15.1 Global Temporary Tables


The global temporary table is the only kind of temporary table where the
schema is permanently recorded in the system catalog tables. The schema per-
sists until the table is explicitly dropped, and the table is available to all
connections. The data, however, is partitioned separately for each connection, as
if each connection owned its own copy of the table.
Like global permanent tables, global temporary tables are created ahead of
time and then used by whatever connections need them. Like local temporary
tables, the data inserted by one connection is invisible to all other connections.
<create_global_temporary_table> ::= CREATE GLOBAL TEMPORARY TABLE
[ <owner_name> "." ] <table_name>
<table_element_list>
[ <commit_action> ]
<table_name> ::= <identifier>
<commit_action> ::= ON COMMIT DELETE ROWS
| ON COMMIT PRESERVE ROWS
| NOT TRANSACTIONAL
It doesnt matter if the table name begins with a number sign or not; a global
temporary table is created either way.
A global temporary table can have the same list of table elements as a
global permanent table: one or more column definitions plus any table con-
straints and properties that might apply.
The commit action controls what happens to the data when a COMMIT or
ROLLBACK is executed. ON COMMIT DELETE ROWS means that all the
data will be deleted when a COMMIT is executed, that changes will be rolled
back when a ROLLBACK is executed, and that otherwise the data persists until
explicitly deleted or the connection is dropped. This is the default behavior, and
often comes as a surprise during testing: Where did all my data go? All I did
was commit!
ON COMMIT PRESERVE ROWS means that a COMMIT will commit the
changes instead of deleting all the data. This is useful during long processes
where commits are frequently done to free locks. Here is an example that shows
that COMMIT and ROLLBACK behave normally with ON COMMIT
PRESERVE ROWS; only the second row shows up in the SELECT:
CREATE GLOBAL TEMPORARY TABLE t (
c1 INTEGER )
ON COMMIT PRESERVE ROWS;

INSERT t VALUES ( 1 ); -- gets rolled back


ROLLBACK;
INSERT t VALUES ( 2 ); -- gets committed
COMMIT;
INSERT t VALUES ( 3 ); -- gets rolled back
ROLLBACK;
SELECT * FROM t; -- only shows row # 2

You might also like