top of page

DB2 Tables Cheat Sheet

  • Writer: Jha Chandan
    Jha Chandan
  • Aug 30, 2021
  • 1 min read

Db2 Tables are logical structure maintained by Database manager. In a table each vertical block called as column (Tuple) and each horizontal block called as row (Entity). The collection of data stored in the form of columns and rows is known as a table. In tables, each column has different data type. Tables are used to store persistent data.

ree

In this blogpost you will see and learn Db2 Tables related syntaxes and methods which help you using Db2 database product.


Creating Tables

db2 create table <schema_name>.<table_name>
(column_name column_type....) in <tablespace_name> 

Listing table details

db2 select tabname, tabschema, tbspace from syscat.tables    

Listing columns in a table

db2 describe table <table_name>    

Creating table with hidden column

db2 create table <tab_name> (col1 datatype,col2 datatype 
implicitly hidden)   

Inserting data values in table

db2 insert into <tab_name>(col1,col2,...)
 values(val1,val2,..)   

Retrieving values from table

db2 select * from <tab_name>    

Retrieving values from a table including hidden columns

db2 select col1,col2,col3 from <tab_name>    

See the data in the hidden columns

db2 describe table <table_name> show detail   

Altering the type of table columns

db2 alter table <tab_name> alter column <col_name> set data type <data_type>  

Altering column name

db2 alter table <tab_name> rename column <old_name> to <new_name>     

Dropping the tables

db2 drop table <tab_name>     

Delete the entire hierarchy of the table (including triggers and relation)

db2 drop table hierarchy <tab_name>

That's all in this post. If you liked this blog and interested in knowing more about IBM Db2. Please Like, Follow, Share & Subscribe to www.ImJhaChandan.com

Comments


jc_logo.png

Hi, thanks for stopping by!

Welcome to my “Muse & Learn” blog!
Muse a little, learn a lot.✌️

 

Here you’ll find practical SQL queries, troubleshooting tips with fixes, and step-by-step guidance for common database activities. And of course, don’t forget to pause and muse with us along the way. 🙂
 

I share insights on:​​

  • Db2

  • MySQL

  • SQL Server

  • Linux/UNIX/AIX

  • HTML …and more to come!
     

Whether you’re just starting out or looking to sharpen your DBA skills, there’s something here for you.

Let the posts
come to you.

Thanks for submitting!

  • Instagram
  • Facebook
  • X
2020-2025 © TechWithJC

Subscribe to Our Newsletter

Thanks for submitting!

  • Facebook
  • Instagram
  • X

2020-2025 © TechWithJC

bottom of page