If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Checking if a global temporary table exists

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-20-04, 09:55
stscrc stscrc is offline
Registered User
 
Join Date: Oct 2004
Posts: 13
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
Reply With Quote
  #2 (permalink)  
Old 10-20-04, 10:36
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
  #3 (permalink)  
Old 10-20-04, 11:47
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On