DB2: Tables Cheat Sheet

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>

Leave a Reply

Your email address will not be published. Required fields are marked *