DB2 Drop table if exists equivalent

后端 未结 5 2156
既然无缘
既然无缘 2020-12-18 23:07

I need to drop a DB2 table if it exists, or drop and ignore errors.

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-18 23:49

    First query if the table exists, like

    select tabname from syscat.tables where tabschema='myschema' and tabname='mytable'
    

    and if it returns something issue your

    drop table myschema.mytable
    

    Other possibility is to just issue the drop command and catch the Exception that will be raised if the table does not exist. Just put that code inside try {...} catch (Exception e) { // Ignore } block for that approach.

提交回复
热议问题