You are on page 1of 31

Introduction to DB2

By – Aditi Agrawal
Branch – CS C
En. No. - 120198

1 11/4/2015
Contents

• Introduction
• Current Editions
• LUW Editions
• System Architecture
• DB2 Interface
• DB2 Objects
• Storage Groups
• Database
• Tablespace
• Table
• Data types

2 11/4/2015
Content(Cont.)

• Null
• Index
• Referential Integrity
• Referential Integrity - Keys
• References

3 11/4/2015
Introduction
What is DB2?

• Developed by IBM.
• An abbreviation for ‘IBM Database 2’.
• Introduced in June 1983.
• Support the relational model.
• Platform-specific DB2 product.
• Supports SQL.
• Latest version of DB2 is DB2 10.5.

4 11/4/2015
Current Editions
There are 4 products in DB2 family –

• DB2 for Linux, UNIX and Windows (informally known as DB2 LUW).
• DB2 for z/OS (mainframe).
• DB2 for i (formerly OS/400).
• DB2 for VM / VSE.

5 11/4/2015
LUW Editions

IBM has changed the packaging structure in the latest release of DB2
for Linux, Unix and Windows and now offers seven editions –

• Advanced Enterprise Server Edition.


• Advanced Workgroup Server Edition.
• Enterprise Server Edition.
• Workgroup Server Edition.
• Express Edition.
• Developer Edition.
• Express-C.

6 11/4/2015
System Architecture
Major Components of DB2 –

• SSAS (System Services Address Space)


Thread creation, Program tracing, Logging
• DBAS (Database Services Address Space)
Execution of SQLs, Database objects management, buffer
management, Data read/write, etc.
• IRLM (IMS Resource Lock Manager)
Locking
• DDF (Distributed data facility component )
Distributed Database functionality
• SPAS (Stored Procedure Address Space)
For the execution of the stored procedures

7 11/4/2015
DB2 Interface

8 11/4/2015
DB2 Objects

• DB2 manages data through a system of logical and physical


entities called objects.

• Objects that describe the data in the way, users and developers
think about it, are called logical objects.
For example - tables, and views.

• Objects that refer to the way, data is actually stored in the system,
are called physical objects.
For example - database and table space.

9 11/4/2015
DB2 Objects

10 11/4/2015
DB2 Objects Hierarchy

11 11/4/2015
Storage Groups

• A storage group is a named set of storage paths where data can be


stored. Storage groups are configured to represent different classes
of storage available to your database system.

CREATE STOGROUP SG
VOLUMES (V1,V2,V3);

12 11/4/2015
Storage Groups - (Cont.)

• The number volumes in a storage group can be changed dynamically


as shown below.

ALTER STOGROUP STOUDB6


ADD VOLUMES (V4,V5)
REMOVE VOLUMES (V1,V3);

13 11/4/2015
Database

• DB2 database is a set of DB2 structures that include a collection of


tables, their associated indexes, and the table spaces in which they
reside.

• One DB2 system can manage up to 65,279 databases.

14 11/4/2015
Creating a Database
• To create a database use

CREATE DATABASE DB
STOGROUP SG
BUFFERPOOL (BP0, BP32);

• To remove a database use

DROP DATABASE DB;

• To change the definition use


ALTER DATABASE DB
ROSHARE {OWNER, NONE}
STOGROUP SG;

15 11/4/2015
Tablespace

• A tablespace is a storage location where the actual data underlying


database objects can be kept.

• Three types of Tablespace


– Segmented TS (default)
– Simple TS
– Partitioned TS (for large databases)

16 11/4/2015
Creating a TS

• Created under an existing DB using

CREATE TABLESPACE TS
IN DB
PRIQTY 10000
SECQTY 1000
PCTFREE 10
FREEPAGE 63
LOCKSIZE ANY
BUFFERPOOL BP0
SEGSIZE 64

17 11/4/2015
More on TS

• To remove a tablespace use

DROP TABLESPACE TS;

• To change the definition use

ALTER TABLESPACE DB.TS


PRIQTY 200
SECQTY 200
ERASE YES
LOCKSIZE ANY
BUFFERPOOL BP1;

18 11/4/2015
Table

• The collection of data stored in the form of columns and rows is


known as a table.

• Create table using

CREATE TABLE EMPLOYEE


(EMP_NO SMALLINT NOT NULL,
EMP_NAME CHAR(15),
EMP_ADDRESS VARCHAR(25) NOT NULL,
PRIMARY KEY (EMP_NO));

19 11/4/2015
More on Table

• To remove a table
DROP TABLE EMPLOYEE;
• To change the definition
ALTER TABLE EMPLOYEE

For example, to add a new field


ALTER TABLE EMPLOYEE
ADD EMP_SALARY INTEGER;

20 11/4/2015
Data types

• Integer
– 4 bytes (5 if nullable)
• Small int
– 2 bytes (3 if nullable)
• Char(n)
– max. 254 bytes
• Varchar(n)
– max. 4046 bytes
• Time
– 3 bytes (4 if nullable)
• Date
– 4 bytes (5 if nullable)

21 11/4/2015
Data types - (Cont.)

22 11/4/2015
Null

• DB2 adds an extra byte to all nullable columns


• This extra byte has the information whether the field contains NULL
or not
• The NULL values do not participate while taking AVERAGE, SUM,
etc.
• Need to have special care while inserting, updating, or retrieving
nullable fields in the host language program.

23 11/4/2015
Index

• Is a structure used for faster retrieval of data.


• Can be unique or non-unique.
• In DB2, we need to explicitly create a unique index for the primary
key.
• Is stored in B - Tree format.

24 11/4/2015
Index

25 11/4/2015
More on Index

• Indexes are created using


CREATE [UNIQUE] INDEX IDX
ON EMPLOYEE(EMP_NO ASC);

• To remove an index
DROP INDEX IDX;

• To change the definition use


ALTER INDEX IDX;

26 11/4/2015
Referential Integrity

• Referential integrity is a database concept that ensures that


relationships between tables remain consistent.

• There are 3 types of keys –


Unique Key
Primary Key
Foreign Key

27 11/4/2015
Referential Integrity - Keys

• Unique Key

 A unique key is defined in a column (or set of columns) where


no two values are same.
 The columns of a unique key cannot contain null values.
 A table can have multiple unique keys.
 Unique keys are optional and can be defined in CREATE
TABLE or ALTER TABLE statements.

28 11/4/2015
Referential Integrity - Keys

• Primary Key

 A primary key is a key, which is unique in each table.


 A table cannot have more than one primary key, and the
columns of a primary key cannot contain null values.

• Foreign Key

 A foreign key is a column (or set of columns) which is a primary


key in another table.

29 11/4/2015
References

• http://en.wikipedia.org/wiki/IBM_DB2
• http://www-03.ibm.com/software/products/en/db2zos
• http://www-01.ibm.com/software/data/db2/linux-unix-windows/
• http://www.cs.umd.edu/class/spring2002/cmsc434-
0101/MUIseum/applications/db2.html
• http://www.webopedia.com/TERM/D/DB2.html
• http://searchdatacenter.techtarget.com/definition/DB2

30 11/4/2015
31 11/4/2015

You might also like