Vous êtes sur la page 1sur 78

DB Concepts

DB Concepts TRANSPARENCIES

DB2_Tr Ver. 1.0.0 04/12/1998

Page 1 of 75

TRADITIONAL FILE PROCESSING SYSTEMS

DB2_Tr Ver. 1.0.0 04/12/1998

Page 2 of 75

TRADITIONAL FILE PROCESSING SYSTEMS (Contd..)


Design focuses on the data processing needs of individual departments. User requests are met by developing new application programs. No overall plan or model to guide the growth of applications. Each new application is typically designed with it's own set of data files. Much of the data in these files could be already present in existing files for other applications.
DB2_Tr Ver. 1.0.0 04/12/1998 Page 3 of 75 3

TRADITIONAL FILE PROCESSING SYSTEMS (Contd..)


Problems in restructuring the existing files.
Files are tailored to an application's need. Each program "owns" its data files, and the program logic is dependent on the file layout. Modifying existing files for use in new applications will require the old programs to be recompiled and/or modified. Hence often far simpler to design new files for each application.

DB2_Tr Ver. 1.0.0 04/12/1998

Page 4 of 75

TRADITIONAL FILE PROCESSING SYSTEMS (Contd..)


Disadvantages of File Processing Systems
Uncontrolled Redundancy. Inconsistent Data. Inflexibility. Limited Data Sharing. Less Data Independence. Poor Enforcement of Standards. Excessive Program Maintenance. No Concept of Transaction.

DB2_Tr Ver. 1.0.0 04/12/1998

Page 5 of 75

DATABASE .

DB2_Tr Ver. 1.0.0 04/12/1998

Page 6 of 75

DATABASE (Contd..)
Why Database ?
Application needs constant changing. Rapid access is frequently required to answer ad hoc queries. Many data elements must be shared by users throughout the organization. Need to communicate data across department boundaries. Need to improve the consistency of data. Need to control access to data.

DB2_Tr Ver. 1.0.0 04/12/1998

Page 7 of 75

DATABASE (Contd..)
What is a Database ?
Shared collection of interrelated data capable of serving multiple applications. Two important properties Integrated Shared Integrated : Distinct data files are logically organized to reduce redundancy. Shared : All qualified users in the organization have access to the data.

DB2_Tr Ver. 1.0.0 04/12/1998

Page 8 of 75

DATABASE (Contd..)
Benefits (Contd...)
Maintains links between related data Reduces data redundancy.
Saves space.

Improves data consistency. Less redundancy and greater sharing leads to less confusion. Centralized control over data standards & security.

DB2_Tr Ver. 1.0.0 04/12/1998

Page 9 of 75

DATABASE (Contd..)
Benefits (Contd...)
Data Independence Data organization and access techniques do not have to be built into the code of every application using the data. It can be categorized in two ways :
Logical Data Independence. Physical Data Independence.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 10 of 75

10

DATABASE (Contd..)
The Database Approach - Benefits (Contd...)
Logical Data Independence
Users and user programs are independent of the logical structure of the database. So Growth of the database is possible, in order to incorporate new kinds of information. e.g. The expansion of an existing base table to include a new column. The inclusion of a new base table in a database. These kinds of changes normally do not have any effect on existing users/programs.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 11 of 75

11

DATABASE (Contd..)
The Database Approach - Benefits (Contd...)
Physical Data Independence Degree to which a program is unaffected by changes to the storage structure.
e.g. In DB2 it is possible to remove an index from the database without having to change or recompile the programs that have used that index.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 12 of 75

12

DATABASE (Contd..)
Benefits (Contd...)
Data Integrity. Ensuring the correctness of database contents. Values in a database can become invalid due to the following :
Values specified incorrectly (mistyping). Two or more data modification transactions individually operate correctly. But their interaction can produce invalid results. Eg :Two agents allocate the same seat to different customers.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 13 of 75

13

DATABASE (Contd..)
Benefits (Contd...)
Concept Of Transaction What is a Transaction ?
A logical unit of work.

What is Transaction Processing?


Here the transaction either executes completely or is totally cancelled. It gives data consistency.

What is Transaction Recovery?


A transaction begins with BEGIN TRANASCTION and ends with either COMMIT or ROLLBACK. COMMIT point (Syncpoint) corresponds to the end of a logical unit of work. ROLLBACK rolls the database to the previous commit.
DB2_Tr Ver. 1.0.0 04/12/1998 Page 14 of 75

DATABASE (Contd...)
Benefits (Contd....)
Database Failure and Recovery Failures can be broadly categorized of two types :
System Failure Media Failure

System Failure : Eg. Power supply, which effects all current transactions. It do not physically damage the database. So here, the current transactions effected due to system failure will either Undo or Redo. Recovery for such failure is CHECKPOINT.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 15 of 75

DATABASE (Contd...)
Benefits (Contd.....)
Database Failure and Recovery (Contd..) CHECKPOINT
When Checkpoint occurs on a database, two tasks are performed : force to write database buffer to physical storage. Writing Checkpoint record to physical log. Checkpoint record consist of list of all transactions that were in progress when checkpoint occurred.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 16 of 75

DATABASE (Contd....)
CHECKPOINT (Contd.)
Time tc tf

T r a n s a c t i o n s

T 1 T 2 T3 T 4 T5

Checkpoi nt (time tc)

System.fail ure (Time tf)

DB2_Tr Ver. 1.0.0 04/12/1998 Page 17 of 75

Status of Transactions during system failure

DATABASE (Contd....)
Benefits (Contd.....)
Database Failure and Recovery (Contd..) Media Failure : Eg. Hard disk crash, which cause physical damage to database and effects those transactions currently using that portion. Here there is no need to Undo or Redo transactions that were in progress at the time of media failure. Recovery for such failure is to use backups or redump/reload utility to restructure the whole database.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 18 of 75

DATABASE (Contd....)
Benefits (Contd....)
Audit Trail It is a special file or a database in which system keeps track of all operations performed by users on regular database. It is required when :
when the data is sufficiently sensitive. The processing performed on the data is very critical. To know the person who is leading the data-discrepancies.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 19 of 75

DATABASE (Contd.....)
Benefits (Contd.....)
Concurrency It is said to occur when many transactions access the same data at the same time. We can look at three common concurrency problems :
The lost update problem. The uncommitted dependency problem. The inconsistent analysis problem.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 20 of 75

DATABASE (Contd.....)
Benefits (Contd......)
The Lost Update Problem

Transaction A FETCH R

TIME T1 T2

Transaction B ---FETCH R ---UPDATE R

UPDATE R

T3 T4

Transaction A loses an update at time T4 because Transaction B overwrites it without even looking at it

DB2_Tr Ver. 1.0.0 04/12/1998 Page 21 of 75

DATABASE (Contd.....)

Three Concurrency Problems (Contd.)


The Uncommitted Dependency Problem-1 Transaction A TIME Transaction B

T1 FETCH R T2

UPDATE R

T3 ROLLBACK

Transaction A becomes dependent on an uncommitted change at time T2

DB2_Tr Ver. 1.0.0 04/12/1998 Page 22 of 75

DATABASE (Contd......)

Benefits (Contd......) Three Concurrency Problems (Contd..)


The Uncommitted Dependency Problem-2 Transaction A TIME Transaction B

T1 UPDATE R T2 T3

UPDATE R

ROLLBACK

Transaction A updates an uncommitted change at time T2 and loses that update at time T3

DB2_Tr Ver. 1.0.0 04/12/1998 Page 23 of 75

DATABASE (Contd.......) Three Concurrency Problems (Contd..) The Inconsistent Analysis Problem Here transaction A is adding ACC1,ACC2 and ACC3
transaction B is transferring 10 from ACC3 to ACC1.

ACC 1 40

ACC 2 50

ACC 3 30

Transaction A
FETCH ACC1 sum = 40 FETCH ACC2 sum = 90

TIME Transaction B
T1 T2 T3 T4 T5 T6 T7 FETCH ACC3 UPDATE ACC3

30-- 20
FETCH ACC 1 UPDATE ACC 1

40-- 50
COMMIT FETCH ACC3 T8 sum = 110 NOT 120

DB2_Tr Ver. 1.0.0 04/12/1998 Page 24 of 75

DATABASE (Contd.......)
Benefits (Contd......)
Locking The standard mechanism to deal with concurrency is LOCKING. In general locks can be of two types :
Shared Lock (S) Exclusive Lock. (X)

Availability of locks.
Locks S X For S lock Y N For X lock N N

DB2_Tr Ver. 1.0.0 04/12/1998 Page 25 of 75

DATABASE (Contd.....)

Locking Services(Contd.)
Locking The Uncommitted Dependency Problem-1 Transaction A TIME Transaction B T1 FETCH R T2 (S lock on R) wait T3 Resume : FETCH R (S lock on R) T4 UPDATE R (X lock on R)

SYNCPOINT
(Release X lock on R)

Transaction A is prevented from seeing an uncommitted change at time T2

DB2_Tr Ver. 1.0.0 04/12/1998 Page 26 of 75

DATABASE (Contd.....)
Locking Services(Contd.)
Locking - The Lost Update Program Transaction A FETCH R TIME Transaction B T1 T2 UPDATE R
(request X lock on R)

(acquire S lock on R)

FETCH R (S lock on R)

T3 T4 UPDATE R
( X lock on R)

wait wait wait wait wait

T5 T6

No update is lost, but deadlock occurs at time T4


DB2_Tr Ver. 1.0.0 04/12/1998 Page 27 of 75

DATABASE (Contd.....)
Locking Services(Contd.)
Locking The Uncommitted Dependency Problem-2 Transaction A TIME Transaction B T1 UPDATE R (X lock on R) wait T2 T3 Resume : UPDATE R T4 (X lock on R)
Here A is prevented from updating an uncommitted change at time T2

UPDATE R (X lock on R)

SYNCPOINT
(Release X lock on R)

DB2_Tr Ver. 1.0.0 04/12/1998 Page 28 of 75

DATABASE (Contd.....)
Locking Services (Contd.)
Locking - The Incosistent Analysis Problem
ACC 1 40 ACC 2 50 ACC 3 30

Transaction A
FETCH ACC 1 (S lock) sum = 40 FETCH ACC 2 (S lock) sum = 90

TIME Transaction B
T1 T2 T3 T4 FETCH ACC3 (S lock on ACC 3) UPDATE ACC3

FETCH ACC 3 (S lock on ACC 3) wait

(X lock on ACC 3) 30 -->20 T5 FETCH ACC 1 (X lock on ACC 1) T6 UPDATE ACC ` 40 --> 50 wait T7 T8 wait

Inconsistent analysis is prevented, but deadlock occurs at T7.


DB2_Tr Ver. 1.0.0 04/12/1998 Page 29 of 75

DATA CONCEPTS AND CHARACTERISTICS


Entity
Any object or event about which the organization chooses to collect and store data. Tangible entity. An employee. A customer. A product. Intangible entity. A bank account. A cost centre.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 30 of 75

30

DATA CONCEPTS AND CHARACTERISTICS (Contd..)


Attribute
Property of entity that we choose to record. Example : Entity Attributes : Customer : Customer Code Customer Name Address Telephone Credit limit

DB2_Tr Ver. 1.0.0 04/12/1998 Page 31 of 75

31

DATA CONCEPTS AND CHARACTERISTICS (Contd..)


Entity Class
Collection of entities that possess similar characteristics. Each entity must have an attribute which can uniquely identify it from other entities in that class.This unique attribute of an entity is called a key. Employee number is a unique key for an employee within an organization. Product Code is the key for a product. Associations may exist between two entity classes or entities.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 32 of 75

32

DATA CONCEPTS AND CHARACTERISTICS (Contd..)


Entity vs Entity Occurrence
PRODUCT # DESCRIPTION COLOUR UNIT PRICE

564

FAN

WHITE

800

DB2_Tr Ver. 1.0.0 04/12/1998 Page 33 of 75

33

DATA CONCEPTS AND CHARACTERISTICS (Contd..)


Key
A data item used to identify a record. Two basic types : Primary Key. Secondary Key. Concatenated Key. A primary key is a data item that uniquely identifies a record. A secondary key normally does not uniquely identify a record. In fact, it normally identifies a number of records that share the same value of some other attribute.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 34 of 75

34

DATA CONCEPTS AND CHARACTERISTICS (Contd..)


Concatenated Keys
Some data items cannot be uniquely identified by a simple primary key that consists of one data item. A primary key that consists of two or more data items is required to identify these records. Such a key is called a concatenated key. e.g. Both Order # and Product # are required to identify the QuantityOrder.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 35 of 75

35

DATA CONCEPTS AND CHARACTERISTICS (Contd..)


Association between Data Items
An association is a logical, meaningful relation between data items. Values for the associated data items are dependent on each other. A database contains thousands of data items and there are many possible associations among these. Fortunately many associations are meaningless and are of no interest to the organization. Each type of data item is diagramatically represented by an ellipse or "bubble".
DB2_Tr Ver. 1.0.0 04/12/1998 Page 36 of 75 36

DATA CONCEPTS AND CHARACTERISTICS (Contd..)


Association between Data Items (Contd..) Types Of Associations (Contd..)
Associations.
If there is an association from data item A to data item B there is also a reverse association from B to A.

A A A

B B B

1:1 1:N M:N

DB2_Tr Ver. 1.0.0 04/12/1998 Page 37 of 75

37

DATA CONCEPTS AND CHARACTERISTICS (Contd..)


Association between Data Items (Contd..) Types Of Associations (Contd..)
Associations (Contd..) Department Department Supplier Manager Employee Part

DB2_Tr Ver. 1.0.0 04/12/1998 Page 38 of 75

38

THREE SCHEMA ARCHITECTURE


Need to provide different views of the data for different users.
Example : A salesperson will require information about Customer and Sales data. However, an accountant will require views of Product and invoice data.

Hence a need for three distinct levels or views of a data base.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 39 of 75

39

THREE SCHEMA ARCHITECTURE (Contd..)


ANSI/SPARC Architecture for a database system is divided into 3 level.
Conceptual level : An integrated view of the entire data base. External or user view level : View of each individual user or application program.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 40 of 75

40

THREE SCHEMA ARCHITECTURE (Contd..)


ANSI/SPARC Architecture for a database system is divided into 3 level.
Internal Level or implementation view Describes how the data base is actually stored and managed on computer secondary storage. Describes records, files, indexes, and other physical storage constructs.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 41 of 75

41

THREE SCHEMA ARCHITECTURE (Contd..)


External View
A Schema is a logical model of a data base. A DBMS that provides these three levels is said to support Three Schema Architecture.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 42 of 75

42

THREE SCHEMA ARCHITECTURE (Contd..)


External (PL/I) Emp# char(6), Sal Fixed(3), External (Cobol) 01 Emprec pic x(6) 02 emprec pic x(6) 02 Deptno pic x(4) Conceptual EMPLOYEE Employee-number Character (6) Dept-Number Salary Internal Employee Length = 18 Character(4) Numeric(5)

Emp# Type=Byte(6), offset = 0 Dept# Type=Byte(6), offset = 6 Index

: : : :

DB2_Tr Ver. 1.0.0 04/12/1998 Page 43 of 75

DATABASE MANAGEMENT SYSTEM (DBMS)


DBMS is the software component of a Database System that is responsible for all access to the database. Handles data definition, data retrieval & data control functions. Supports concurrent data access and update. Provides services for Data security, Recovery, and Integrity.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 44 of 75

44

DBMS (Contd..)
DBMS stands between the user and data, insulating the user from the actual physical storage medium. Hence, user cannot interact with the stored data directly. User requests DBMS to obtain a specific record from the database. DBMS is built upon the foundation provided by existing file access methods.
e.g. DB2 uses VSAM access method as its storage strategy.

The file access services of the DBMS retrieve the requested data.
DB2_Tr Ver. 1.0.0 04/12/1998 Page 45 of 75 45

DBMS (Contd..)

DB2_Tr Ver. 1.0.0 04/12/1998 Page 46 of 75

46

DBMS (Contd..)

DB2_Tr Ver. 1.0.0 04/12/1998 Page 47 of 75

47

DBMS (Contd..)
DBMS are categorized by the manner in which they present the data to the user.
Hierarchical data model uses tree structure to represent data. Example : IMS Network model is the same as hierarchical model other than it allows many to many relationships i.e. one child linked to many parents. Example : IDMS Relational model shows data in the form of tables. Example : DB2
DB2_Tr Ver. 1.0.0 04/12/1998 Page 48 of 75 48

Hierarchical Model
An Example
Consider a database containing records for various courses selected by various students. In the Hierarchical Model, the logical representation would be :

Student Student Code Name

A102

Amit Singh
Marks

Parent record

Course Course Code Name

C01 C03

English

86 94

Science

C06 Economics 81

DB2_Tr Ver. 1.0.0 04/12/1998 Page 49 of 75

49

Hierarchical Model (Contd..)


Features
One student (parent or root) record can have multiple course (child) records. Each course (child) record can further have child child records, it can have child-child-child records & so on upto any level. A child record cannot exist without its parent record. A child record must have exactly one parent record (one-many relationship). The application program must know the hierarchy in which data is stored. Similar requirements need entirely different programs to be written.
DB2_Tr Ver. 1.0.0 04/12/1998 Page 50 of 75 50

Network Model
An Example
Student Code Student Name

A101 Atul Kahate

A102 Amit Singh

C01
Course Code

English
Course Name

C02 Maths C03

Science

C06 Economics

DB2_Tr Ver. 1.0.0 04/12/1998 Page 51 of 75

51

Network Model (Contd..)


Features
One child record can have one or multiple parent records Parent & child records can exist irrespective of the existence of the other Links or connectors represent the relationships between parents & children

DB2_Tr Ver. 1.0.0 04/12/1998 Page 52 of 75

52

Network Model (Contd..)


Features (Contd..)
Unlike in Hierarchical model, the program logic for different types of requests is similar. Network model introduces symmetry in program logic which is absent in Hierarchical model. Network model improves upon the Hierarchical model from the view of the application programs.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 53 of 75

53

Network Model (Contd..)


Drawback of Network Model
The main drawback of this model is its complexity in terms of the data structure itself and DML.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 54 of 75

54

Relational Model
Example
Representation of student-course database using Relational Model
Student Code A101 A102 Student Name Atul Kahate Amit Singh Course Code C01 C02 C03 C06 Marks 87 85 83 86 94 81 Course Name English Maths Science Economics

Student Code A101 A101 A101 A102 A102 A102

Course Code C01 C02 C03 C01 C03 C06

DB2_Tr Ver. 1.0.0 04/12/1998 Page 55 of 75

55

Relational Model (Contd..)


Features
No concept of parents or children. Unlike Network model, absence of connectors Interrelationship of data indicated by values in tables alone

Operations
Insert, Update or Delete - None poses a problem as all tables are independent of each other

DB2_Tr Ver. 1.0.0 04/12/1998 Page 56 of 75

56

Advantage of Relational Over Hierarchical & Network Models


No special operators to describe navigation. No pointers or links connecting one table to another.
Connection is achieved through common column values.

Links between the associated tables are made by the DBMS. User specifies only what data is to be accessed and not how to access it. Increases the simplicity of the request.
DB2_Tr Ver. 1.0.0 04/12/1998 Page 57 of 75 57

E. F. Codds 12 rules
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. The Information rule The rule of guaranteed access The systematic treatment of NULL values rule The database description rule The comprehensive data sub-language rule The view updation rule The insert, update and delete rule The physical data independence rule The logical data independence rule Integrity independence rule Distribution independence rule Non-subversion rule

DB2_Tr Ver. 1.0.0 04/12/1998 Page 58 of 75

58

RELATIONAL DATABASE MANAGEMENT SYSTEM (RDBMS) A DBMS based on the relational model is called Relational Database Management System (RDBMS). RDBMS presents complete information content of the database as a collection of tables. An ideal RDBMS should satisfy Codds rules.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 59 of 75

59

RDBMS (Contd..)
A table is made up of rows and columns. One table for each entity. One row for each instance (occurrence) of the entity. One column for each attribute of the entity.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 60 of 75

60

RDBMS (Contd..)
All data values are atomic.
Within each row, only one value exists for each column. Valid table
S# ---S2 S2 S4 S4 S4 P# ---P1 P2 P2 P4 P5

Invalid table
S# ---S2 S4 P# ---(P1, P2) (P2, P4, P5)

DB2_Tr Ver. 1.0.0 04/12/1998 Page 61 of 75

61

RDBMS (Contd..)
Total collection of all values that may occur within a given column is its domain. All data in a given column must be of the same type. Table can contain a maximum of 300 columns. A row is the smallest unit of data that can be inserted or deleted. Data is presented with values at the intersection of a row and column. Rows and columns are not stored in any specific order.
DB2_Tr Ver. 1.0.0 04/12/1998 Page 62 of 75 62

RDBMS (Contd..)
No duplicate rows are allowed.
Those columns which are responsible for ensuring row's uniqueness are the table's PRIMARY KEY. A primary key may consist of one column or multiple columns.

Relationships between tables are made through values in the tables.


Columns which maintain this link are FOREIGN KEYS.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 63 of 75

63

RDBMS (Contd..)

DB2_Tr Ver. 1.0.0 04/12/1998 Page 64 of 75

64

RDBMS (Contd..)

Terminologies
------------------------------------------------------------Relational RDBMS Conventional ------------------------------------------------------------Relation Table File Tuple Attribute Degree Cardinality Row Column Number of Columns Number of Rows Record Occurrence Field Number of Fields Number of Records

DB2_Tr Ver. 1.0.0 04/12/1998 Page 65 of 75

65

NORMALIZATION
Process of successive reduction of a given collection of relations to some more desirable form. Data items are combined to form relations in such a manner so as to :
Achieve controlled redundancy. Avoid anomalies arising due to Insertion, Updation and Deletion

DB2_Tr Ver. 1.0.0 04/12/1998 Page 66 of 75

66

NORMALIZATION (Contd..)
Advantages of Normalization
Improves the maintainability of the data structures. Adding or dropping an entity is a simple matter of adding or deleting a table. Adding an attribute requires only the altering of a table to add a column. Reduces complex user views to a set of small stable data structures. Adding a relationship also requires only the addition of a foreign key column.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 67 of 75

67

NORMALIZATION (Contd..)
Advantages of Normalization
Relations are normalized by simplifying them into normal forms. There are mainly three normal forms. First Normal Form. Second Normal Form. Third Normal Form.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 68 of 75

68

NORMALIZATION (Contd..)

Consider the following Employee example :

Employee Employee Name Number

Job Job Code Title

Project Number

Completion Date

Hours Worked

This can be represented in tabular form as follows:


Emp. Emp. No. Name 120 120 120 121 121 125 Jones Jones Jones Thomas Thomas James Job Code 01 01 01 11 11 01 Job Title Prog. Prog. Prog. Ana. Ana. Prog. Project No. 01 08 02 01 08 02

Completion
Date 7/17 1/12 3/21 7/17 1/12 3/21

Hours Worked 37 30 21 20 15 20

In this example (Employee Number, Project Number) is the Primary Key


DB2_Tr Ver. 1.0.0 04/12/1998 Page 69 of 75 69

NORMALIZATION (Contd..)
First Normal Form (1NF or FNF)
The intersection of each row and column should contain only one value. Relational tables are automatically in the First Normal Form.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 70 of 75

70

NORMALIZATION (Contd..)
First Normal Form (Contd..)
FNF may contain highly redundant data resulting in the following problems : Insertion : A project cannot be entered unless there are employees working on it. Deletion of a record of an only employee working on a project causes project details also to be deleted. Suppose an employee job is to be changed. It involves searching and updating of several records of that employee.
71

Deletion :

Updation :

DB2_Tr Ver. 1.0.0 04/12/1998 Page 71 of 75

NORMALIZATION (Contd..)
Second Normal Form (2NF or SNF) :
Relation has to be in First Normal Form Every non-key attribute has to be fully functionally dependent on the primary key. In the above example : Employee Name, Job Code, Job Title are functionally dependent on Employee Number only. Hours-worked is functionally dependent on combination of Employee Number and Project Number. Completion Date is functionally dependent on Project Number only.
DB2_Tr Ver. 1.0.0 04/12/1998 Page 72 of 75 72

NORMALIZATION (Contd..)
Second Normal Form (Contd..)
EMPLOYEE Employee Number 120 121 125 129 Employee Name Jones Thomas James Mark Job Code 01 11 01 08 Job Title Prog. Ana. Prog. Des.

PROJECT Proj No. 01 08 02 09 Completion Date 7/17 1/12 3/21 4/11


73

DB2_Tr Ver. 1.0.0 04/12/1998 Page 73 of 75

NORMALIZATION (Contd..)

Second Normal Form (Contd..)


HOURS
Employee No. 12 120 120 120 121 125 125 129 129 129 Project No. 01 08 02 01 08 02 09 01 09 08 Hours Worked 37 30 21 20 15 20 43 30 20 25

Now we can add Employee or Project records independent of each other.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 74 of 75

74

NORMALIZATION (Contd..)
Second Normal Form (Contd..)
Insertion : A Job Title cannot be
entered for a Job Code unless there is an employee doing that job.

Deletion :

If there is only one employee doing a particular job, deletion of that record causes job details also to be deleted. If the Job Code is changed for a particular Job Title, it involves a lot of searching and updating of records for that Job.
75

Updation :

DB2_Tr Ver. 1.0.0 04/12/1998 Page 75 of 75

NORMALIZATION (Contd..)
Third Normal Form (3NF or TNF) :
Any non-key attribute should not be transitively dependent on the primary key. In the above SNF example : The Job Title is functionally dependent on Job Code and Job Code is functionally dependent on Employee Number. This means that the Job Title is transitively dependent on Employee Number.

DB2_Tr Ver. 1.0.0 04/12/1998 Page 76 of 75

76

NORMALIZATION (Contd..)
Third Normal Form (Contd..)
EMPLOYEE Emp. No. 120 121 125 129 Emp. Name Jones Thomas James Mark Job Code 01 11 01 08 JOBS Job Code 01 11 08 Job Title Prog. Ana. Des.

PROJECT Proj. No. 01 08 02 09 Completion Date 7/17 1/12 3/21 4/11


77

DB2_Tr Ver. 1.0.0 04/12/1998 Page 77 of 75

NORMALIZATION (Contd..)
Third Normal Form (Contd..)
HOURS
Employee No. 12 120 120 120 121 125 125 129 129 129 Project No. Hours Worked 01 08 02 01 08 02 09 01 09 08 37 30 21 20 15 20 43 30 20 25

DB2_Tr Ver. 1.0.0 04/12/1998 Page 78 of 75

78

Vous aimerez peut-être aussi