Metadata Queries: Listing a Table's Columns
DB2
Query SYSCAT.COLUMNS:
select colname, typename, colno from syscat.columns where tabname = 'EMP' and tabschema = 'SMEAGOL'
Oracle
Query ALL_TAB_COLUMNS:
select column_name, data_type, column_id from all_tab_columns where owner = 'SMEAGOL' and table_name = 'EMP'
PostgreSQL, MySQL, and SQL Server
Query INFORMATION_SCHEMA.COLUMNS:
select column_name, data_type, ordinal_position from information_schema.columns where table_schema = 'SMEAGOL' and table_name = 'EMP'
Each vendor provides ways for you to get detailed information about your column data. In the examples above only the column name, data type, and position are returned. Additional useful items of information include length, nullability, and default values