DB2 Drop Table question

Posted on 2011-10-24
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 ?
Question by:Los Angeles1
    1 Comment
    LVL 37

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    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…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now