1

我有一个表列表,我想检查目标数据库中当前不存在哪些表,我无法找出只返回列表中不存在的表的查询?我正在运行 DB2 9.7。

4

1 回答 1

2

如果您要检查的表列表是您可以查询的形式,它将是这样的。下面的查询将返回不在选择表查询中的所有表(您必须提供):

select * from sysibm.systables
where owner = 'SCHEMA'
and type = 'T'
and name not in ( /* select query to return your list of tables */ );

更新帖子评论:

如果表格列在平面文件(.txt、.csv)中并且数量是可管理的。您应该能够像这样以逗号分隔的形式列出它们(至少您可以使用我更熟悉的其他 sql 语言)。

select * from sysibm.systables
where owner = 'SCHEMA'
and type = 'T'
and name not in ( 'table1', 'table2', 'table3', 'table4', 'tableA', 'tableB' );

否则,您可能必须构建一个快速临时表以将所有表名导入并继续使用第一个示例。


更新帖子发表评论:

最后,在您最近发表评论之后,我意识到我误解了您的问题并将其倒退。要翻转它并从列表中找到不在 SCHEMA 中的表,您可以执行以下操作。(将列表导入临时表后)。

select mytablename from templistoftables
where mytablename not in 
(select name from sysibm.systables
where owner = 'SCHEMA'
and type = 'T');
于 2012-10-15T02:49:10.813 回答