3 Neat SQL Queries to View Table Structure in DB2

Here’re SQL queries to view the Table structure in DB2. It helps you to write SQL queries correctly. For that matter, these three SQL queries helpful for you.

3 Top SQL Queries to See Table Structure

  1. Use DESCRIBE
  2. Use SYSIBM.SYSCOLUMNS
  3. Use DB2LOCK

1. With 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.

2. 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.

Here’s more on Oracle-SQL-ultimate-experience

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.

SQL E-Book
1
  • 32 COMPLEX SQL QUERIES
DB2 E-Book
1
  • DB2 TOUGH INTERVIEW QUESTIONS

Related Posts

Get new content delivered directly to your inbox.

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.