Académique Documents
Professionnel Documents
Culture Documents
INTRODUCTION TO DATABASE
MANAGEMENT SYSTEMS
Definition
Data Base is a collection of data stored in a well
organized manner
Advantages of database
Characteristics of DBMS
Data Independence
Speedy handling of spontaneous information
requests
Non-Redundancy
Versatility in representing relationships
between data items
Security protection
Real-time accessibility
Hierarchical Database
The Data in this database is stored in the form
of Segments. The Segments will have ParentChild relationship.
One Parent segment can have more than one
Child Segments and one Child Segment can
not have more than one Parent Segment,
Network Database
The data stored in this type of database in the
form of records and links
Here one record can have more dependent
records and the same record can have more
superior records also, I.e., Many-To-Many
approach
Ex. IDMS
Relational Database
The data in this type of database is stored in
the form of Tables.
The relationship between Tables can be
maintained by using Primary key and Foreign
Key relationship
Ex. DB2, Oracle, Sybase etc..
RELATIONAL DATABASE
MANAGEMENT SYSTEM
DB2
DB2 is a relational database developed by
IBM for computers running under MVS
DB2 can be connected to CICS, IMS, TSO
(These three environments provide services
like data communication and control of
transactions)
RDBMS Terminology
The data in Relational data base is stored in
Table/Relation in terms of rows and columns
Rows are called TUPLES and columns are
called ATTRIBUTES
No.of attributes is called as ORDER
No.of Tuples is called as CARDINALITY
Primary key
It represents a single column or group of columns and
performs the unique identification of rows(records) in
table
Alternate key
It is a alternate key to search table, need not maintain
uniqueness
Referential Integrity
If table-1 includes a foreign key FK matching the
primary key PK of table-2 , then every value of FK in
the first table must either be equal to the value of PK
in the second table, then Referential integrity is
ensured b/w two tables
Relational Operators
Union, Union All
Combining two or more tables or part of
tables in row fashion
ex. Select empname from emp where deptno=10
UNION
select empname from emp where deptno=20
Union All eliminates duplicates
Join
Combining two or more tables or part of
tables in column fashion
There is no Join operator in DB2, but we can
achieve it through Select statements
There are Internal Join and Outer Join, Internal
Join looks for matching values of both
columns of two tables where as Outer Join
does not look for matching.
ex. Select empsal.*, emppsnl.* from empsal,
emppsnl where empid.empsal= empid.emppsnl
Normalization:
It is a formal process of developing data
structures in a manner that eliminates
redundancy and promotes integrity.
This normalization can be achieved generally
by using three forms
1) Elimination of repeating groups
2) Elimination of Partial key dependencies
3) Elimination of inter key dependencies
varchar(50));
Runtime Supervisor
It is resident in the main memory when the
application program is executing.
When the program requests some database
operation to be performed, control first goes to
the runtime supervisor, which uses the control
information in the application plan to request
the appropriate on the part of the Data Manager.
Data Manager
It performs all the normal access method
functions- search, retrieval, update, index
maintenance, etc., and also manages the
Physical Databases.
It invokes other system components as
necessary in order to perform detailed
functions such as locking, logging, I/O
operations, etc.
Numeric:
Small int(two bytes), Integer(four bytes),
Decimal(x,y), float(n)
Date and time:
Date --> mmddccyy
Time --> hhmmss
Time stamp --> mmddccyyhhmmssnnnnnn
STRUCTURED QUERY
LANGUAGE (SQL)
Contd...
LIKE:
For partial search of a columns LIKE is used.
ex.a)Select empid from emp where empname
LIKE -am-
b)select empid from emp where empmane
LIKE sub%
Subquery
It is a query having another query inside the
main query is called subquery
Ex.SELECT ename FROM emp WHERE
d.no=(SELECT d.no FROM dept WHERE Loc =
chennai)
Correlated subquery
It is a subquery executed for each qualified row
in the outer query.
Ex.1 SELECT name, salary FROM emp WHERE
emp.salary > (SELECT AVG(dept.salary) FROM
dept WHERE emp.deptno=dept.deptno)
Note:
DB2 APPLICATION
DEVELOPMENT
BIND:
It involves in creating executable code for the
Host variable
It is a storage space provided by the host language
for the variables declared in sql queries. Purpose is to
store the query result in the corresponding host
variable.
Null
when we dont supply values for a column of
specified record, null will be supplied by the
system.
Not Null
This option specifies that the column cant have
nulls, always values to be supplied for the columns
declared as Not Null.
Generally KEY fields(columns) are defined with
NOT NULL option.
CURSOR Technique
In CURSOR technique, we can process
multiple rows unlike one row in singleton
select. Cursor technique can be achieved by
four steps , those are
1)Declare cursor
EXEC SQL
DECLARE empcursor CURSOR
FOR
SELECT empno,sex,age FROM
employee
END-EXEC
2)Open cursor
EXEC SQL
OPEN empcursor
END-EXEC
3)Fetch cursor
EXEC SQL
FETCH empcursor INTO : ws-emp-no,
ws-sex, ws-age
END-EXEC
4) Close cursor
EXEC SQL
CLOSE empcursor
END-EXEC
EXEC SQL
DECLARE empcursor CURSOR
FOR SELECT empno, salary FROM emp FOR
UPDATE OF salary
END-EXEC
EXEC SQL
UPDATE emp SET salary=:ws-salary
WHERE CURRENT OF empcursor
END-EXEC
EXEC SQL
WHENEVER condition action
END-EXEC
EXEC SQL
INCLUDE SQLCA
END-EXEC
procedure Division.
MOVE consultancy TO pa-cry-dept.
EXEC SQL
OPEN empcursor
END-EXEC.
SET ws-fetch-not-over-cn TO TRUE.
PERFORM Modify-sal-para
THRU Modify-sal-para-exit
UNTIL ws-fetch-over-cn.
EXEC SQL
CLOSE empcursor
END-EXEC.
STOP RUN.
Modify-sal-para.
EXEC SQL
FETCH empcursor
INTO :empno, :name, :dept, :salary
END-EXEC.
EVALUATE
SQLCODE
WHEN SQLCODE < 0
PERFORM X-error-para
THRU X-error-para-exit
DB2 INTERNALS
Database Objects
Storage Group
It is set of DASD volumes given a particular
name By using CREATE STORAGE GROUP we
can create storage group
Data Base
It is collection of table spaces and index spaces.By
using CREATE DATABASE we create data base.
Table space
Table spaces are used to store the tables. These
are three types, Simple table space, Segmented
table spaces, Partitioned table spaces
Table
Combination of rows and columns
INDEX
Index is an ordered set of pointers to rows of a base
table. Key has to be supplied for creation of an index
To create index, use CREATE INDEX syntax
VIEW
It is window to the table, may be combination of tables
or part of a table. Views are not updatable if the view
is combination two tables
ex. CREATE VIEW empview (empno, name) AS
(SELECT empno, name FROM emp) WHERE
salary < 3000
SYNONYM
It is an alternate name for a table. The purpose is to
hide the information location of the table It can be
accessed only by the user who creates it, mainly used
in local sub systems, it will be dropped when table is
dropped
1) Cursor Stability
In this type of isolation level, lock held until
next fetch
By using this we can avoid last update
problem
2) Repeatable read
In this type of isolation level, lock held until
end of unit of work
Incorrect summary is eliminated
Dead lock
It is a situation in which two or more
transactions are in simultaneous wait state,
each wait for one of others to release a lock on
object before it can proceed. Transaction
manager will take care this problem suggests
for roll back of the task
Recovery
The data in database will be recovered by
using Recover utility, when any problem
occurs like system crash, is called Recover of
database.
Active Log
It is DASD dataset used to write the DB2 log
record (containing data changes and
significant changes as they occur) is called
Active Log.
Archive log
When Active log is full DB2 copies its
contents to DASD or TAPE dataset called
Archive log.
Off-Loading
The process of transferring data from Active
log to Archive log is called Off-Loading.
COMMIT
By issuing this command the database changes
will be updated and establishes a syncpoint
Roll back
When any unsuccessful end-of-transaction
happens, to undo all the changes upto the last
syncpoint (boundary b/w two transactions),
roll back command is used.