DB2删除表(如果存在) [英] DB2 Drop table if exists equivalent

查看:1109
本文介绍了DB2删除表(如果存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除一个DB2表(如果存在),或者删除并忽略错误.

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

推荐答案

第一次查询表是否存在,例如

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

其他可能性是仅发出drop命令并捕获如果表不存在将引发的异常.只需将代码放入try {...} catch(Exception e){//忽略}块中即可.

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.

这篇关于DB2删除表(如果存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆