Database Design: Logical Design-Part2
Database Design: Logical Design-Part2
Database Design:
Logical Design-Part2
Introduction
Steps For Designing
Database
Conceptual Design STEP 1
STEP 2
Logical Design
STEP 3
STEP 4 STEP 6
STEP 5 STEP 7
Physical Design
STEP 8
STEP 9
Methodology Overview -
Conceptual Database Design
Step
1 Build local conceptual data
model for each user view
Step 1.1 Identify entity types
Step 1.2 Identify relationship types
Step 1.3 Identify and associate attributes with entity or
relationship types
Step 1.4 Determine attribute domains
Step 1.5 Determine candidate and primary key attributes
Step 1.6 Consider use of enhanced modeling concepts (optional
step)
Step 1.7 Check model for redundancy
Step 1.8 Validate local conceptual model against user transactions
Step 1.9 Review local conceptual data model with user
Methodology Overview - Logical
Database Design for Relational
Model
Step2 Build and validate local logical
data model for each view
Step 2.1 Remove features not compatible with the
relational model (optional step)
Step 2.2 Derive relations for local logical data model
COMPANIES(company_name, company_address,
date_founded, owner_id, owner_name,
owner_title, #shares )
Example of Update
Anomalies
To insert a new staff with branchNo B007 into the
StaffBranch relation;
To delete a tuple that represents the last member of staff
located at a branch B007;
To change the address of branch B003.
StaffBranch
staffNo sName position salary branchNo bAddress
SL21 John White Manager 30000 B005 22 Deer Rd, London
SG37 Ann Beech Assistant 12000 B003 163 Main St,Glasgow
SG14 David Ford Supervisor 18000 B003 163 Main St,Glasgow
SA9 Mary Howe Assistant 9000 B007 16 Argyll St, Aberdeen
SG5 Susan Brand Manager 24000 B003 163 Main St,Glasgow
SL41 Julie Lee Assistant 9000 B005 22 Deer Rd, London
Branch
branceNo bAddress
B005 22 Deer Rd, London
B007 16 Argyll St, Aberdeen
B003 163 Main St,Glasgow
COMPANIES(company_name, company_address,
date_founded, owner_id, owner_name,
owner_title, #shares )
Delete Anomaly
Suppose that an owner of a company retires so is no longer
an owner but retains stock in the company
If this person’s tuple is deleted from the COMPANIES
relation, then we lose the information about how much
stock the person still owns
If the stock information was stored in a different relation,
then we can retain this information after the person is
deleted as an owner of the company
COMPANIES(company_name, company_address,
date_founded, owner_id, owner_name,
owner_title, #shares )
Relationship Between
Normal Forms
Steps For Normalization
Unnormalized Form
Second
Normalized Form
(2NF)
Third
Normalized Form
(3NF)
Unnormalized A table that contains one or more repeating groups
Form (UNF)
… … … … … … … …
SALESPERSON
First Normal {PK}
SALESPERSON
NUMBER
SALESPERSON
NAME
SALES
AREA
… … …
SALESPERSON-CUSTOMER
SALESPERSON CUSTOMER CUSTOMER NAME WAREHOUSE WAREHOUSE SALES
{PK} NUMBER NUMBER NUMBER LOCATION AMOUNT
… … … … … …
A Data Model Diagarm
(SALESPERSON-CUSTOMER)
SALES
AMOUNT
CUSTOMER
NAME
SALESPERSON CUSTOMER
NUMBER NUMBER
WAREHOUSE
NUMBER
WAREHOUSE
LOCATION
SALESPERSON CUSTOMER SALES
Second
NUMBER AMOUNT
SALES NUMBER
3462 18765 13540
3462 18830 10600
(2NF)
3593 18841 11560
CUSTOMER-WAREHOUSE … … …
… … … …
SALESPERSON CUSTOMER SALES
SALESPERSON SALES NUMBER NUMBER AMOUNT
CUSTOMER-WAREHOUSE … … …
… … … …
A Data Model Diagram
(CUSTOMER-WAREHOUSE)
CUSTOMER
CUSTOMER
NAME
NUMBER
WAREHOUSE
NUMBER
WAREHOUSE
LOCATION
WAREHOUSE
Form (3NF) 4
3
Fargo
Bismarck
18841 R.W.Flood 2
18899 Seward 2
19565 Stodola 1
… … …
SALESPERSON SALES
SALESPERSON CUSTOMER SALES
SALESPERSON SALESPERSON SALES
NUMBER NUMBER AMOUNT
{PK} NUMBER NAME AREA
3462 18765 13540
3462 18830 10600
3462 Waters West
3593 Dryne East 3462 19242 9700
… … …
3593 18841 11560
… … …
18765 Delta Sys. 4
18830 Levy & Sons 3 WAREHOUSE
WAREHOUSE WAREHOUSE
19242 Ranier Com 3 {PK} NUMBER LOCATION
4 Fargo
18841 R.W.Flood 2
3 Bismarck
18899 Seward 2
2 Superior
19565 Stodola 1
1 Plymouth
… … … … …
Boyce-Codd Form (BCNF)
A more restricted version of 3NF (known as Boyce-
Codd Normal Form) A relation is in BCNF, if
and only if, every determinant is a candidate
key.
Consider the following relation:
StaffProject(StnNo,PjcNo, StaffNo);
StnNo,PjcNo -> StaffNo (primary key)
StaffNo,StnNo -> PjcNo (candidate key)
StaffNo -> PjcNo (not a candidate key)
Boyce-Codd Normal Form for above:
Project(PjcNo, StnNo);
Staff(StaffNo, PjcNo)
Conceptual Level,
Conceptual Schema,
Logical Design,
Logical Data Model
CASE 1
B is functionally
A B
dependent on A
Determinant
Refers to the attribute or group of
attributes on the left-hand side of
the arrow of a functional
dependency
First Normal Form (1NF)
6 lawrence Tina
1-Jul-00 31-Aug-01 350 CO40 Murphy
PG4 St,Glasgow
John
CR76
kay Tony
PG16 5 Novar Dr, Shaw
1-Sep-02 1-Sep-02 450 CO93
Glasgow
6 lawrence Tina
PG4 1-Sep-99 10-Jun-00 350 CO40 Murphy
St,Glasgow
Tony
Aline 2 Manor Rd,
CR56 PG36 10-Oct-00 1-Dec-01 370 CO93 Shaw
Stewart Glasgow
Tony
5 Novar Dr, Shaw
PG16 1-Nov-02 1-Aug-03 450 CO93
Glasgow
6 lawrence Tina
CR76 PG4 1-Jul-00 31-Aug-01 350 CO40
St,Glasgow Murphy
5 Novar Dr, Tony
CR76 PG16 1-Sep-02 1-Sep-02 450 CO93
Glasgow Shaw
6 lawrence Tina
CR56 PG4 1-Sep-99 10-Jun-00 350 CO40
St,Glasgow Murphy
2 Manor Rd, Tony
CR56 PG36 10-Oct-00 1-Dec-01 370 CO93
Glasgow Shaw
5 Novar Dr, Tony
CR56 PG16 1-Nov-02 1-Aug-03 450 CO93
Glasgow Shaw
(Partial dependency)
fd4 ownerNo oName
(Transitive Dependency)
fd5 clientNo, rentStart propertyNo, pAddress,
rentFinish, rent, ownerNo, oName
(Candidate key)
fd6 propertyNo, rentStart clientNo, cName, rentFinish
(Candidate key)
2NF ClientRental
relation
Client (clientNo, cName)
Rental (clientNo, propertyNo, rentStart, rentFinish)
PropertyOwner (propertyNo, pAddress, rent, ownerNo, oName)
Client Rental
ClientNo cName ClientNo propertyNo rentStart rentFinish
CR76 John Kay CR76 PG4 1-Jul-00 31-Aug-01
CR56 Aline Stewart CR76 PG16 1-Sep-02 1-Sep-02
CR56 PG4 1-Sep-99 10-Jun-00
CR56 PG36 10-Oct-00 1-Dec-01
CR56 PG16 1-Nov-02 1-Aug-03
PropertyOwner
Client
fd2 clientNo cName (Primary Key)
Rental
fd1 clientNo, propertyNo rentStart, rentFinish (Primary Key)
fd5 clientNo, rentStart propertyNo, rentFinish (Candidate key)
fd6 propertyNo, rentStart clientNo, rentFinish (Candidate key)
PropertyOwner
fd3 propertyNo pAddress, rent, ownerNo, oName (Primary Key)
fd4 ownerNo oName (Transitive Dependency)
3NF ClientRental
relation
The resulting 3NF relations have the forms:
Client
(clientNo, cName)
Rental
(clientNo, propertyNo, rentStart, rentFinish)
PropertyOwner
(propertyNo, pAddress, rent, ownerNo)
Owner
(ownerNo, oName)
3NF ClientRental
relation
Client Rental
ClientNo propertyNo rentStart rentFinish
ClientNo cName
CR76 PG4 1-Jul-00 31-Aug-01
CR76 John Kay
CR56 Aline Stewart CR76 PG16 1-Sep-02 1-Sep-02
CR56 PG4 1-Sep-99 10-Jun-00
CR56 PG36 10-Oct-00 1-Dec-01
CR56 PG16 1-Nov-02 1-Aug-03
PropertyOwner Owner
3NF already
BCNF 3NF
Client Rental
already
ClientNo propertyNo rentStart rentFinish BCNF
ClientNo cName
CR76 PG4 1-Jul-00 31-Aug-01
CR76 John Kay
CR56 Aline Stewart CR76 PG16 1-Sep-02 1-Sep-02
CR56 PG4 1-Sep-99 10-Jun-00
CR56 PG36 10-Oct-00 1-Dec-01
3NF CR56 PG16 1-Nov-02 1-Aug-03
already
PropertyOwner BCNF
Owner
3NF
propertyNo pAddress rent ownerNo
ownerNo oName already
PG4 6 lawrence St,Glasgow 350 CO40 BCNF
CO40 Tina Murphy
PG16 5 Novar Dr, Glasgow 450 CO93
CO93 Tony Shaw
PG36 2 Manor Rd, Glasgow 370 CO93
Example of BCNF
fd1 clientNo, interviewDate interviewTime, staffNo, roomNo (Primary Key)
fd2 staffNo, interviewDate, interviewTime clientNo, roomNo (Candidate key)
fd3 roomNo, interviewDate, interviewTime clientNo, staffNo (Candidate key)
fd4 staffNo, interviewDate roomNo (not a candidate key)
As a consequece the ClientInterview relation may suffer from update anomalies. For
example, two tuples have to be updated if the roomNo need be changed for staffNo SG5 on
the 13-May-02.
ClientInterview
ClientNo interviewDate interviewTime staffNo roomNo
CR76 13-May-02 10.30 SG5 G101
CR56 13-May-02 12.00 SG5 G101
CR74 13-May-02 12.00 SG37 G102
CR56 1-Jul-02 10.30 SG5 G102
As a consequece the ClientInterview relation may suffer from update anomalies. For
example, two tuples have to be updated if the roomNo need be changed for staffNo SG5 on
the 13-May-02.
ClientInterview
ClientNo interviewDate interviewTime staffNo roomNo
CR76 13-May-02 10.30 SG5 G101
CR56 13-May-02 12.00 SG5 G101
CR74 13-May-02 12.00 SG37 G102
CR56 1-Jul-02 10.30 SG5 G102
StaffRoom
staffNo interviewDate roomNo
SG5 13-May-02 G101
SG37 13-May-02 G102
SG5 1-Jul-02 G102