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

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

问题描述

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

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

推荐答案

先查询表是否存在,like

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) {//Ignore } 块中即可.

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天全站免登陆