sql - Get biggest tables and check if column exists in these tables (one query) -
i want list biggest tables , check if tables have column logsys.
like:
db2 "select t.tabname,t.npages,(select count(c.colname) syscat.columns c c.tabname = t.tabname , c.colname = 'logsys') syscat.tables t t.tabschema = 'own' order t.npages desc fetch first 3 rows only"
- is way? there better way?
- the execution running without ending (or end days later... :-( )
the output should show if 1 of these biggest tables, has column named logsys (all tables should list in output of sql statement).
this version might bit more efficient, since there can 1 column specified name in each table:
select t.tabname, t.npages, case when exists (select 1 syscat.columns c c.tabname = t.tabname , c.tabschema = t.tabschema , c.colname = 'logsys') 1 else 0 end syscat.tables t t.tabschema = 'own' order t.npages desc fetch first 3 rows
note both tabname
, tabschema
needed uniquely identify table.
Comments
Post a Comment