Sybase IQ recognizes four types of tables.
Base tables
Local temporary tables
Global temporary tables
Join virtual tables
Base tables are sometimes called main, persistent, or permanent tables because they are a permanent part of the database until you drop them explicitly.
They remain in the database over user disconnects, server restart, and recovery. Base tables and the data in them are accessible to all users who have the appropriate permissions. The CREATE TABLE statement shown in the previous example creates a base table.
There are two types of temporary tables, global and local.
You create a global temporary table, using the GLOBAL TEMPORARY option of CREATE TABLE, or by using the Global Temporary Table Creation wizard in Sybase Central.
When you create a global temporary table, it exists in the database until it is explicitly removed by a DROP TABLE statement.
A database contains only one definition of a global temporary table, just as it does for a base table. However, each user has a separate instance of the data in a global temporary table. Those rows are visible only to the connection that inserts them. They are deleted when the connection ends, or commits. A given connection inherits the schema of a global temporary table as it exists when the user first refers to the table. Global temporary tables created on a multiplex server are also created on all other multiplex servers. See Using Sybase IQ Multiplex > Multiplex Transactions > DML Commands > Table Data Scope.
SELECT * INTO #TableTemp FROM lineitem WHERE l_discount < 0.5
You declare a local temporary table for your connection only, using the DECLARE LOCAL TEMPORARY TABLE statement. A local temporary table exists until the connection ends or commits, or within a compound statement in which it is declared. The table and its data are completely inaccessible to other users.
An attempt to create a base table or a global temporary table will fail, if a local temporary table of the same name exists on that connection, as the new table cannot be uniquely identified by owner.table.
You can, however, create a local temporary table with the same name as an existing base table or global temporary table. References to the table name access the local temporary table, as local temporary tables are resolved first.
CREATE TABLE t1 (c1 INT); INSERT t1 VALUES (9); DECLARE LOCAL TEMPORARY TABLE t1 (c1 INT); INSERT t1 VALUES (8); SELECT * FROM t1;The result returned is 8. Any reference to t1 refers to the local temporary table t1 until the local temporary table is dropped by the connection.