Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Posts
    13

    Unanswered: Checking if a global temporary table exists

    Since global temporary tables are not stored in syscat.tables, is it possible to check if a global temporary table exists via a SQL statement?

    I want my code to create the global temorary table only if it doesn't already exist.

    Thanks,
    Mark

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    You can create the GTT and then check for SQLSTATE value ... If your SQLSTATE value is 0 or that of 'Object already exists' continue to your next step

    Cheers
    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    I am not sure if this will work for you, but you could use the "WITH REPLACE" option on the DECLARE GTT statement. This will create the table if it does not exist. But if the table does exists, it will effectively drop the existing definition and replace it with the new, including all the data in the existing GTT.

    Andy

Posting Permissions

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