Upload
aditi212
View
76
Download
1
Tags:
Embed Size (px)
Citation preview
Introduction to DB2
By – Aditi Agrawal
Branch – CS C
En. No. - 120198
11/4/20151
Contents
• Introduction
• Current Editions
• LUW Editions
• System Architecture
• DB2 Interface
• DB2 Objects
• Storage Groups
• Database
• Tablespace
• Table
• Data types
11/4/20152
Content(Cont.)
• Null
• Index
• Referential Integrity
• Referential Integrity - Keys
• References
11/4/20153
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.
11/4/20154
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.
11/4/20155
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.
11/4/20156
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
11/4/20157
DB2 Interface
11/4/20158
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.
11/4/20159
DB2 Objects
11/4/201510
DB2 Objects Hierarchy
11/4/201511
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);
11/4/201512
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);
11/4/201513
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.
11/4/201514
Creating a Database
• To create a database use
• To remove a database use
DROP DATABASE DB;
• To change the definition use
CREATE DATABASE DB
STOGROUP SG
BUFFERPOOL (BP0, BP32);
ALTER DATABASE DB
ROSHARE {OWNER, NONE}
STOGROUP SG;
11/4/201515
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)
11/4/201516
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
11/4/201517
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;
11/4/201518
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));
11/4/201519
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;
11/4/201520
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)
11/4/201521
Data types - (Cont.)
11/4/201522
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.
11/4/201523
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.
11/4/201524
Index
11/4/201525
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;
11/4/201526
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
11/4/201527
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.
11/4/201528
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.
11/4/201529
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
11/4/201530
11/4/201531