Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 1: DB2 Introduction


What is DB2?

DB2, short for Database 2, is IBM's relational database management system (RDBMS). It stores data in tables and lets programs and users retrieve and change that data using SQL.

DB2 as a relational database management system

  • In 1970, Dr. E. F. Codd developed a new model for representing data, called the relational model.
  • A relational database uses tables to store and manipulate data. DB2 is built on this model.
  • DB2 is a Database Management System: it stores information electronically, makes it shareable by users or programs, and provides security, recovery and consistency.
  • DB2 runs on IBM mainframe computers, AS/400 midrange computers and PCs.

How a DB2 table is organized

  • Each table has one or more rows, also called records.
  • Each row contains one or more columns, also called fields.
  • The data in a specific column of a specific row is called a value.
  • Tables may have a primary key: a column (or columns) that uniquely identifies each row in the table.
  • An index can be applied to any column in a table so DB2 can find rows faster.
  • Tables are related through their key fields. For example, a customer table has CUSTNO as its primary key, and an invoice table has INVCUST as a foreign key that points back to CUSTNO.

Creating a table: example

  • The CREATE TABLE statement below defines a new table in DB2:-
    CREATE TABLE USER.PERIODIC_BALANCES (CUSTOMER_NO CHAR(11) NOT NULL, BALANCE_PERIOD SMALLINT NOT NULL, BALANCE DECIMAL(15,2), PRIMARY KEY (CUSTOMER_NO, BALANCE_PERIOD) )
  • CREATE TABLE is a DDL statement: it defines a new database object.
  • CUSTOMER_NO and BALANCE_PERIOD together form the primary key, so no two rows may share both values.
  • CHAR(11), SMALLINT and DECIMAL(15,2) are DB2 data types describing what each column can hold.
  • NOT NULL means the column must always have a value; DB2 rejects rows that leave it empty.

What DB2 does for you

  • Stores data centrally so many programs and users can share it safely.
  • Enforces rules (keys, NOT NULL) so bad data is rejected at the database itself, not in every program.
  • Lets you ask ad-hoc questions with SQL instead of writing a new program for every report.
  • Recovers data after failures and protects it with security controls.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant