DB2 Tables Cheat Sheet
- 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.

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