Sunteți pe pagina 1din 1

Chapter 1: Creating 35

PRIMARY KEY ( pkey ) );

INSERT INTO t1 VALUES ( 1, 'Hello, World' );


COMMIT;
On the second database the following commands create the server, external
login, and two proxy tables. The first proxy table t1proxy points to the existing
table t1, and the second proxy table t2proxy causes a new table t2 to be created
on the remote database:
CREATE SERVER other CLASS 'ASAODBC' USING 'otherdsn';

CREATE EXTERNLOGIN DBA TO other


REMOTE LOGIN DBA IDENTIFIED BY "SQL";

CREATE EXISTING TABLE t1proxy AT 'other;otherdb;dba;t1';

SELECT * FROM t1proxy; -- displays 'Hello, World'

CREATE TABLE t2proxy (


pkey INTEGER NOT NULL,
c1 VARCHAR ( 20 ) NOT NULL,
PRIMARY KEY ( pkey ) )
AT 'other;otherdb;dba;t2';

INSERT INTO t2proxy VALUES ( 1, 'Goodbye' );

SELECT * FROM t2proxy; -- displays 'Goodbye'

1.15 Temporary Tables


Temporary tables are different from permanent tables in terms of the location
and life span of the data. A permanent tables data is stored in the database file
and it lasts until it is explicitly deleted. The data in a temporary table is never
stored in the actual database file, and it never lasts longer than the connection
that inserted it in the first place. The server keeps temporary table data in mem-
ory, and if there isnt room in memory the server will use a special temporary
file that is separate from the database file. The server only creates one tempo-
rary file per database, and it gets deleted when the server is shut down.
Temporary tables are very useful in complex applications. They allow pro-
grams to load and process raw input data before storing it in permanent tables.
They also permit a divide and conquer approach to writing huge queries; tem-
porary tables can be loaded with parts of an original query and then combined in
a final, simpler query. Sometimes the optimizer can do a better job with several
smaller queries, with the overall execution being much faster.
A temporary table is often used in a stored procedure that returns a result
set. The procedure can use a cursor loop or whatever other complex techniques
are required to load the temporary table, then it executes SELECT * FROM on
that table to return a simple result set. This approach can be used to transform
non-relational data from external sources into relational data for further
processing.

S-ar putea să vă placă și