SQL - info about table / columns

By kimot, 24 December, 2022

This SQL can be useful when you need basic info about SQL schemas

QSYS2.SYSTABLES view contain information about every table, view or alias in the SQL schema :

SELECT table_name, 
       system_table_name, 
       table_schema, 
       table_type, 
       table_owner, 
       column_count, 
       row_length, 
       table_text, 
       long_comment, 
       file_type
FROM QSYS2.SYSTABLES
WHERE table_name = 'AUTHORIZATION_LIST_USER_INFO' 
  AND table_schema='QSYS2';

QSYS2.SYSCOLUMNS view contain information about columns in table, view or alias in the SQL schema :

SELECT system_column_name, 
       column_name, 
       table_name, 
       ordinal_position, 
       data_type, 
       length, 
       numeric_scale, 
       column_heading
FROM QSYS2.SYSCOLUMNS
WHERE table_name = 'AUTHORIZATION_LIST_USER_INFO' 
  AND table_schema='QSYS2';