Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2006
    Posts
    11

    Question Unanswered: DB2 equivalent for mysql's DROP TABLE IF EXISTS

    Hi,


    I'd wonder if there's a way to do something like mysql's
    Code:
    DROP TABLE IF EXISTS <tablename>
    in DB2?

    Peter

  2. #2
    Join Date
    Jul 2006
    Location
    Pune , India
    Posts
    433
    hi Peter

    Use the db2perf_quiet_drop procedure. The source code is available on
    ftp://ftp.software.ibm.com/ps/produc...perf-1.0.1.zip
    In the file db2perf_utils.db2 there is the procedure db2perf_quiet_drop
    which suppresses the 'not found' message.
    The call :
    CALL db2perf_quiet_drop( 'procedure db2perf_crmsg' )@
    drops the procedure db2perf_crmsg if this procedure exists

    regards,
    Rahul Singh

  3. #3
    Join Date
    Mar 2006
    Location
    Bogota, Colombia
    Posts
    21
    You can use an annonymous block

    BEGIN
    DECLARE CONTINUE HANDLER FOR SQLSTATE '42704'
    BEGIN END;
    EXECUTE IMMEDIATE 'DROP TABLE sometable';
    END @
    AngocA

  4. #4
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    SET V_EXISTS = (SELECT 1 FROM SYSCAT.TABLES WHERE TABSCHEMA = yourTableSchema AND TABNAME = yourTableName);
    IF (V_EXISTS IS NOT NULL) THEN
    EXECUTE IMMEDIATE 'DROP TABLE ' || yourTableSchema || '.' || yourTableName;
    END IF;
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

Posting Permissions

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