Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2007
    Posts
    1

    Wink Unanswered: Temporary Tables in DB2

    Hi All!

    I would like to ask your expertise in DB2 SQL scriptingÜ I just transferred to I2 team who are using DB2-AIX. I am just new to DB2 environment and is using MS SQL Server on my previous team.

    Now I would like to ask if there are Temporary Table here in DB2?

    Give this simple SQL Code (in MS SQL Server 2000), what would be its equivalent in DB2 SQL?

    Code
    SELECT * INTO #tempTable from ITEMS_TABLE

    Creating temporary tables in MS SQL Server is pretty much easy since I just have to assign the set of records using INTO to the assigned temporary table with the "#" sign.

    It would be a great help if I will be able to apply this since it will save processing time.


    Another thing:
    What would be the equivalent script for checking if database object exists here in DB2? Below would be the sample code in MS SQL Server 2000.

    Code
    IF OBJECT_ID('tempdb.dbo.#outDT') IS NOT NULL
    DROP TABLE dbo.#outDT
    GO
    :

    Thank you and God Bless,
    MaDz angel:

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    In DB2, you need to first declare the temp table. See DECLARE GLOBAL TEMPORARY TABLE in the SQL Reference Vol 2.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    Jan 2003
    Posts
    1,605
    khickyphutz, I suggest to download a free DB2 Cookbook. Just "save link as" from link "DB2 9 SQL Cookbook (1290K)". Then see the section Temporary tables on page 273.
    Hope this helps,
    Grofaty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •