You are on page 1of 5

Chapter 2.

Exploring the Capabilities of DB2 Universal Database

Relational Database:
A DB2 database is a relational database. The database stores all data
in tables that are related to one another. Instead of repeating data in different
tables, relationships are established between tables such that data is shared
and duplication is minimized. There are internal DB2 features and functions
that establish and maintain these relationships. Each database includes a set
of system catalog tables that describe the logical and physical structure of
the data. There can be more than one database per instance.

Tables, Columns and Rows:


Data is stored in logical structures called tables. A table consists of
data logically arranged in a finite number of columns and rows. The
maximum number of row in a table is 4 times 10 to 9 th power times the
number of partitions in the database. A base table is created with the
CREATE TABLE statement and is used to hold persistent user data. A
result table is a set of rows that the database manager selects of generates
from one or more base tables to satisfy a query from a user or application.

Views:
Views allow you to view selected data from one or more tables. A
view is also known as a virtual table. You can see all of the columns or
rows contained in one or more table, which also means that views can be
used to restrict or limit user’s access to data. “No permanent storage is
associated with a view”. A view is simply the named specification of a
result table.
Syntax of Creating View:

CREATE VIEW <view name> AS <full select>

Schemas:
A schema is an identifier, similar to a user ID, used to group table and
other database objects together. The owner of the schema controls the
access to the data and the objects within the schema. A schema is also an
object in the database. The schema can be explicitly created by using the
CREATE SCHEMA statement.
Keys:
A Key is one or more columns used o identify, or access, a particular
row or rows in a table. When creating a table, index or referential constraint,
a key must be identified. A given column can be part of more than of keys.
There are several different types of keys:
1) Composite Key: A Composite key is made up of more than one
column. The ordering of the columns within the composite key is not
constrained by their order within the table.
2) Unique Key: A Unique key is constrained so that no two of its
values are equal, and as result, the columns of a unique key cannot contain
null values. The mechanism used to enforce the constraint is calling a
unique index, and it is the database manager that enforces the constraint.
Database operations can change the values in the columns of a unique key,
and when that happens, the database manager checks to see whether any
constraints have been violated.
3) Primary Key: A Primary key is a special case of a unique key.
There is only one primary key for each table.
4) Foreign key: A Foreign key is a key that is specified in the in the
definition of a referential constraint.

Packages:
A package is an object stored in the database that includes information
needed to run SQL statements in a single source file. A database application
uses one package for every precompiled source file used to build the
application. Each package is a separate entity and has no relationship to any
other packages used by the same or other applications. Database applications
use packages for some of the same reasons applications are compiled
improved performance and compactness. Binding is the process that creates
the package the database manager needs in order to access the database
when the application is run. Binding takes the bind file created by the
precompiled and creates a database manager package. Rebinding is the
process of recreating a package for an application program that was
previously bound. You must rebind packages if they have been marked
invalid or inoperative. If a package depends on another database object and
that object is dropped, the package becomes invalid. If the dropped object is
a user-defined function, the package becomes inoperative.
Data Types:
Each column of every DB2 table is given an SQL data type when the
column is created. For information about how these types are assigned to
columns, refer to the CREATE TABLE statement in the SQL Reference. The
database manager supports the following column data types:

SMALLINT
16-bit signed integer.

INTEGER
32-bit signed integer. INT can be used as a synonym for this type.

BIGINT
64-bit signed integer.

DOUBLE
Double-precision floating point. DOUBLE PRECISION and
FLOAT(n) (where n is greater than 24) are synonyms for this type.
REAL Single-precision floating point. FLOAT(n) (where n is less than 24)
is a synonym for this type.

DECIMAL
Packed decimal. DEC, NUMERIC, and NUM are synonyms for this
type.

CHAR
Fixed-length character string of length 1 byte to 254 bytes.
CHARACTER can be used as a synonym for this type.

VARCHAR
Variable-length character string of length 1 byte to 32672 bytes.
CHARACTER VARYING and CHAR VARYING are synonyms for
this type.

LONG VARCHAR
Long variable-length character string of length 1 byte to 32 700 bytes.
CLOB Large object variable-length character string of length 1 byte to 2
gigabytes (2GB). BLOB Large object variable-length binary string of
length 1 byte to 2 gigabytes.
DATE Character string of length 10 representing a date.

TIME Character string of length 8 representing a time.

TIMESTAMP
Character string of length 26 representing a timestamp.
The following data types are supported only in double-byte character set
(DBCS) and Extended UNIX Code (EUC) character set environments.

GRAPHIC
Fixed-length graphic string of length 1 to 127 double-byte characters.

VARGRAPHIC
Variable-length graphic string of length 1 to 16336 double-byte
characters.
LONG VARGRAPHIC
Long variable-length graphic string of length 1 to 16 350 double-byte
characters.

DBCLOB
Large object variable-length graphic string of length 1 to 1 073 741
823 double-byte characters.

Functions:
A function is a relationship between a set of input data values and a
set of result values. Database functions can be either built-in or user-
defined:
Built-in functions are provided by DB2 and are associated with the
SYSIBM schema.
User-defined function can be registered to a database in the
SYSCAT.FUNCTIONS catalog table. User-defined functions are not
associated with the SYSIBM schema.

Most database functions can be classified as column functions or


scalar functions.
Syntax of creating function is

CREATE FUNCTION <function name>


Roll-Forward Recovery:
To use the roll-forward recovery method, you must have taken a
backup of the database and archived the logs. Active logs are still available
for crash recovery, but you also have the archived logs, which contain
committed transaction data. The two types of roll-forward recovery are:
Database roll-forward recovery: To transactions recorded in database
logs are applied following the database restore operation. The database logs
record all changes made to the database. This method completes the
recovery of the database o its state at a particular point in time or to its state
immediately before the failure.
Table space restore and roll-forward: If the database is enabled for
forward recovery, it is also possible to back up, restore and roll-forward
table spaces. To perform a table space restore and roll-forward operation,
you need a backup image of either the entire database or one or more
individual table spaces. You also need the log records that affect the table
spaces that are to be recovered.

Major Component of DB2:


There are the system services, locking services, database services and
distributed data facility component. The database services component, in
turn, divides into the Precompiled, Bind, Runtime, supervisor, Data Manager
and Buffer Manager Component.

You might also like