I have shared top SQL queries to get Table details. Writing SQL queries is easy if you know the Table structure. So, you can get the Table structure quickly in your projects.
DB2: 3 Top SQL Queries to get Table Structure (Details).
Query-1: Using DESCRIBE
Describe schema.table_name DESCRIBE TSY.MY_FIRST_TABLE DESCRIBE INDEXES FOR TSY.MY_FIRST_TABLE SHOW DETAIL
Here, Describe is the keyword, and “TSY” is the schema name. Finally, the Table name is my_first_table.
In the second query, you will get all the indexes defined.
Query-2: Using SYSIBM.SYSCOLUMS
SELECT * FROM SYSIBM.COLUMNS WHERE TABLE_NAME = 'MY_FIRST_TABLE';
Here, SYSIBM.COLUMNS is a catalog Table. That has a schema of “SYSIBM”. So after running this query, you will get Table details including column names and indexes.
Query-3: Using DB2LOOK
db2look -d dbname -e -t my_first_table
Here, DB2LOOK is the system command. You can issue this command in the command line to know the Table structure in DB2.