Db2:用于搜索具有不同列名的表的查询

Db2:用于搜索具有不同列名的表的查询,db2,db2-luw,Db2,Db2 Luw,在我的数据库中,所有表都应该有一个列,比如说abc,我想找出没有这个列的表。我们有任何这样的疑问来满足这一要求吗 数据库:Db2 v11.1 LUW您可以针对SYSCAT.COLUMNS和SYSCAT.TABLES构建查询,以查找没有此类列的表: select tabname from syscat.tables t1 where not exists (select colname from syscat.columns c where c.tabname=t1.tabnam

在我的数据库中,所有表都应该有一个列,比如说abc,我想找出没有这个列的表。我们有任何这样的疑问来满足这一要求吗


数据库:Db2 v11.1 LUW

您可以针对SYSCAT.COLUMNS和SYSCAT.TABLES构建查询,以查找没有此类列的表:

select tabname from syscat.tables t1
where not exists
    (select colname from syscat.columns c
     where c.tabname=t1.tabname and colname='foo')
and tabname like 'SYSX%'

以上只是一个示例,未进行优化。

仅限非系统表。列名必须为大写,除非您在创建表时有意用双引号将列名指定为“abc”

select tabschema, tabname 
from syscat.tables t
where not exists
(
select 1 
from syscat.columns c
where c.tabschema=t.tabschema and c.tabname=t.tabname 
and c.colname='ABC'
)
and tabschema not like 'SYS%'
and type='T';
可能重复的