On 10-Dec-2011 12:42 , mattes wrote:
Quote:
I am a little bit confused about DB2 temporary tables. (We use MS
SQL Server 2005 at work and we are planning to migrate to DB2.) In
MS SQL Server one can use the following example statement to create
a temporary table (#temp; without defining the columns):
SELECT c1, c2, ... cn INTO #temp
FROM schema.table
WHERE c1> 4;
For me it is an easy way to create temporary tables...
How do I do this in DB2? |
How the temporary would be used, will influence the choice of type
[and thus syntax] for making the temporary table\result available.
DECLARE GLOBAL TEMPORARY TABLE statement
http://publib.boulder.ibm.com/infoce...c/r0003272.htm
DB2 9.7: Created global temporary tables
Learn how and when to use CGTTs
http://www.ibm.com/developerworks/da...obaltemptable/
"... The main difference between a DGTT <ed: Declared Global Temporary
Table> and a CGTT is that the definition of a CGTT is stored
persistently in the DB2 catalog. A DGTT is created and exist only for
the duration of a user session. Unlike DGTTs, CGTTs are created in a
session and persist after the session is terminated. The definition is
shared across all concurrent sessions, even though the content of a
created temporary table remains private to each session. ...
"
CREATE GLOBAL TEMPORARY TABLE statement
http://publib.boulder.ibm.com/infoce.../r0053719.html
DECLARE GLOBAL TEMPORARY TABLE statement
http://publib.boulder.ibm.com/infoce.../r0003272.html
Or limited to a component of a particular query, a
common-table-expression:
Queries and table expressions
http://publib.boulder.ibm.com/infoce...c/c0004116.htm
Select-statement
http://publib.boulder.ibm.com/infoce...c/r0000879.htm
Regards, Chuck