DB2 - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

DB2 Tables

DB2 Tables

shape Description

The DB2 Tables is the essential storage objects for the information in a relational database. It is sorted out as collection of rows and columns. In tables, each and every column has diverse information sort. Tables are utilized to preserve steady information.

Rows

shape Description

A row is record of information in a database table. For example, a row of information in a topography table may comprise of a specific nation code, name of the country, name of the state.

Columns

shape Description

A field also called a column in a relational database, and is a part of a table that is allocated a particular information sort.

Types of tables

shape Description

The DB2 Tables can be classified into the following types, such as:

Base Tables

Base Table holds persistent sort of information and contains different sorts of tables.

Temporary Tables

For transitory tasks of various database transactions, one have to utilize transitory tables. The impermanent tables don't show up in framework index, the columns in XML can't be utilized as a part of creating this impermanent tables.

Materialized Query Tables

Materialized Query Tables are utilized to enhance the execution of inquiries. These sorts of tables are characterized by an inquiry, which is utilized to decide the information in the tables.

Creating a table

shape Description

The DB2 Table can be created with all the necessary datatype and constraints.

shape Syntax

The syntax for creating a DB2 Tables is as follows:
db2 create table <schema_name>.<table_name> (column_name column_type....) in <tablespace_name> Schema_name => All the table_name details will be stored. Table_name => Accurate table name in DB2 database. Tablespace_name => Is a stored table space.

shape Examples

By viewing the below example, the concept of creating a table in DB2 database can be easily understands. [c] db2 => create table experience.employee24(emp_id int, name varchar(50),jobrole varchar(30), salary double) in mydb2 DB20000I The SQL command completed successfully.[/c] Here in the above example a table my name employee24 as been successfully created.

Insert the values

shape Description

The insert table is used to insert the values inside the db2 database table.

shape Syntax

The syntax for inserting the values in DB2 database table is as follows:
db2 insert into <table_name>(column1,column2,...) values(value1,value2,..) Table_name => The accurate table name inside the db2 database. Column => The columns that are inserted in the table. Values => Are the column values.

shape Examples

By viewing the below example, the concept of creating a table in DB2 database can be easily understands. [c] db2 => insert into experience.employee24(emp_id, name, jobrole, salary) values(1001,'David','Manager',25000) db2 => insert into experience.employee24(emp_id, name, jobrole, salary) values(1002,'Mate','Sales',20000) db2 => insert into experience.employee24(emp_id, name, jobrole, salary) values(1003,'James','Database admin',30000) db2 => select * from experience.employee24 emp_id name jobrole salary ------- --------- ------------ ----------- 1001 David Manager 25000 1002 Mate Sales 20000 1003 James Database admin 30000 3 record(s) selected. [/c]

Dropping a table

shape Description

By using Drop command one can drop a table from the existing database.

shape Syntax

The syntax for dropping a table is as follows:
db2 drop table <table_name> Drop => Is used to drop a table from the database. Table_name => Accurate table in the database.

shape Examples

By viewing the below example, the concept of dropping a table in DB2 database can be easily understands. [c] db2 drop table experience.employee24 DB20000I The SQL command completed successfully. [/c] Here in the above example the table name employee24 can be successfully dropped from the db2 database.

Summary

shape Key Points

  • DB2 Table - Is an essential storage object inside the database.
  • Rows - Is a record of information.
  • Column - A field also called as a column.
  • Creating a table - Is created with all necessary datatype and constraints.
  • Insert the values - Is used for inserting the values inside the table.
  • Dropping a table - Is used to drop an existing table from the database.