I have a DB2 table and i want to see which columns are declared NOT NULL.
What are the other constraints of all columns of the table (Primary Key) ?
You have a choice of ways, it depends on your available tooling and it also depends on your Db2-server platform (z/os, i-series, linux/unix/windows/cloud).
query the Db2 catalog with SQL . For Db2-Z/OS (mainframe) the table to query is SYSIBM.SYSCOLUMNS
- the NULLS
column will be N for "NOT NULL". and the column KEYSEQ
will be 0 if the column is not in the primary key, otherwise the value is the column's ordinal position in the primary-key. For Db2-for-i-series (as400), query QSYS2.SYSCOLUMNS
. For Db2-LUW query SYSCAT.COLUMNS
for your tabschema,tabname and look at the value in the NULLS column (N means NOT NULL).
extract the DDL for the table with Db2 tools (for example db2look
for Db2-LUW) or with a GUI tool and the DDL will show the columns that are not null or what columns (if any) form the primary key
if you use a front-end tool on your workstation (e.g IBM Data Studio, DBVisualiser, and many others) they have functionality to let you see the table structure (i.e the DDL) and they are able to work with any Db2-server platform.