Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DB2 Drop Table question

Posted on 2011-10-24
1
Medium Priority
?
302 Views
Last Modified: 2012-06-27
When I drop a table that exists, the command responds successfully

db2 => drop table catalog
DB20000I  The SQL command completed successfully.

Open in new window


When I drop a table that does not exist, the command throws an error

db2 => drop table catalog
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0204N  "DB2INST1.CATALOG" is an undefined name.  SQLSTATE=42704

Open in new window


The problem is that if I place a drop table inside of a script, and the table does not exist, then the script dies and all commands following the 'drop table' command are not executed

Is there any way to keep the drop table command from throwing an error if the table does not already exist ?
0
Comment
Question by:Los Angeles1
1 Comment
 
LVL 37

Accepted Solution

by:
momi_sabag earned 2000 total points
ID: 37019749
short answer - no

long answer - you have two ways to face this problem:
1) create a stored procedure that will receive the table name as a parameter. If the table exists, it will drop it
The stored procedure will always finish successfully

2) Don't know which scripting language you use, but in your script you can try to run a query against syscat.table and see if the table already exists. If yes, drop it, else don't
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question