How to obtain the details of a user table in DB2
1. Get the User Name of the current user
SELECT CURRENT SCHEMA FROM SYSIBM.SYSDUMMY1
2. Obtain the names of all tables under a user.
Select creator, TYPE, NAME, remarks from sysibm. Variables Ables where type = 'T' and creator = 'username' -- case sensitive
3. Obtain the details of a table under the current user.
Select t. TBNAME, -- table name T. NAME, -- field name t. REMARKS, -- Chinese name of the Field T. COLTYPE, -- field type T. LENGTH, -- field length t. SCALE, -- precision T. NULLS -- whether it is null from sysibm. syscolumns t where tbcreator = 'username' and tbname = 'table name'
4. Obtain information about all tables and fields of the current user.
Select. TBNAME, -- English name of the table B. REMARKS, -- Chinese table name B. TYPE, -- object type. COLNO, --. NAME, -- the English NAME of A field. REMARKS, -- Chinese name of the field. COLTYPE, -- field type. LENGTH, -- length. SCALE, -- precision. NULLS, -- whether to allow null C. PK_NAME, -- primary key name C. KEY_SEQ, -- primary key sequence C. COLUMN_NAME -- primary key field name from sysibm. syscolumns a -- Field List table left join sysibm. systables B -- table remarks table (Chinese name of the table) ON. TBCREATOR = B. creator and. TBNAME = B. name left join sysibm. sqlprimarykeys c on. TBCREATOR = C. TABLE_SCHEM and. TBNAME = C. TABLE_NAME and. NAME = C. COLUMN_NAME where B. TYPE = 'T' and. TBCREATOR = 'username' -- TYPE = T: table v: vieworder by. TBCREATOR,. TBNAME,. COLNO