Session 7: Database Design
• Conceptual
– Entity Relationship Modeling
• Logical
– Data Normalization
Logical Database Design
• Design Principles
• Functional Dependencies
• Normal Forms
– 1NF
– 2NF
– 3NF
– BCNF
Design Principles
• Design a relation schema so that it is easy to
explain its meaning.
– Each relation schema should correspond to one entity
type or one relation type
• Design relation schemas so that no insertion,
deletion, or modification anomalies can occur.
– If anomalies can occur take steps to ensure that
programs that update the database operate correctly
Design Principles (continued)
• Avoid placing attributes in a base relation whose
value may be null.
• Design relation schemas so that they can be
JOINed on attributes that are either primary keys
or foreign keys in a way that no spurious tuples
are generated.
• Minimize data redundancy
Functional Dependency
• A functional dependency is a constraint between
two sets of attributes from the database
XY
Y is functionally dependent on X, where X and Y
are subsets of attributes in a relation R
• The values of the X component of a tuple uniquely
determines the values of the Y component
• All attributes in a relation are functionally
dependent on the primary key
Normalization
• Process of decomposing relational schemas into smaller
relational schemas with desirable properties
• Minimizes the risk of update anomalies
• Provides a formal framework for analyzing relational
schemas based on functional dependencies
• The process of normalization must ensure
– lossless (non-additive) join
• spurious tuples should not be created
– dependency preservation
• all functional dependencies must be represented.
Normal Forms
1 NF
2 NF
3 NF
BCNF
Relations in the third normal form and BCNF
typically satisfy the design principles adequately
First Normal Form (1NF)
• All attribute values are single and indivisible
• Multivalued attributes, composite attributes, and
their combinations are not allowed
Consider a schema [A B C] where A is the primary key, B
a set of non-repeated attributes, and C a set of repeated
attributes.
The schema can be decomposed into 1NF schemas
[A B] and [A C] with A combining with the primary key of
C to form the primary key of [A C]
Second Normal Form (2NF)
• A relation schema R is in the second normal form
if every non-prime attribute A in R is fully
functionally dependent on every key of R
• Partial dependencies are not allowed
Consider a relation schema [A B C D E] with a
composite key AB. Let A C and BD
The schema can be decomposed into the 2NF
schemas [A B E] , [A C], and [B D]
Third Normal Form (3NF)
• A relation schema R in in 3NF if every nonprime
attribute is
– Fully functionally dependent on every key of R
– Non-transitively dependent on every key of R
• Transitive dependencies are not allowed
Consider a schema in 2NF [A B C] with BC
The schema may be decomposed into 3NF
schemas [A B] and [B C]
Normal Forms
• A relation is in 1 NF iff all underlying domains
contain scalar values only
• A relation is in 2 NF iff it is in 1 NF and every
non-key attribute is dependent on the entire
primary key
• A relation is in 3 NF iff it is in 2 NF and all non-
key attributes are dependent only on the candidate
keys
Example: Sales Receipt
A/C Number Receipt No
Customer Name Date
Address
City State ZIP
Item Code Description Price Quantity Item Total
Sub Total
Tax
Total
Relations in 1 NF
SALES ORDER ITEM SOLD
Receipt number Item code
Sales date Receipt number
A/c number Description
C Name Price
C Address Quantity
C City Item total
C State
C ZIP
Sub total
Tax
Total
Relations in 2 NF
SALES ORDER ITEM SOLD PRODUCT
Receipt number Item code Item code
Sales date Receipt number Description
A/c number Quantity Price
C Name Item total
C Address
C City
C State
C ZIP
Sub total
Tax
Total
Relations in 3 NF
SALES ORDER CUSTOMER ITEM SOLD PRODUCT
Receipt number A/c number Item code Item code
Sales date C Name Receipt number Description
A/c number C Address Quantity Price
Sub total C City Item total
Tax C State
Total C ZIP
Entity-Relationship Model
• Conceptual modeling tool
• Entity
• Relationship
• Attribute
• Primary Key
• Weak Entity
• Cardinality
• Specialization, Generalization, Aggregation
Example: ER Schema
N WORKS 1
FOR
EMPLOYEE 1 1 DEPT
MANAGES
1
M
WORKS N CONTROLS
ON
1 N N
SUPERVISION
1 PROJECT
DEPENDENTS
OF
N
DEPENDENT
Notations for ER Diagrams
ENTITY TYPE
WEAK ENTITY TYPE
RELATIONSHIP TYPE
IDENTIFYING RELATIONSHIP TYPE
Notations for ER Diagrams
ATTRIBUTE
KEY ATTRIBUTE
MULTIVALUED ATTRIBUTE
COMPOSITE ATTRIBUTE
DERIVED ATTRIBUTE
Examples
Name
DEPARTMENT PhoneNumber
Address NumberofEmployees
Street City ZIP
Notations for ER Diagrams
E1 R E2 Total Participation of
E2 in R
1 N
E1 R Cardinality Ratio
E2
1:N for E1:E2 in R
(min, max) Structural Constraint
R E (min, max) on participation
of E in R
Extended ER Features
• Specialization
– Subclass (ISA) relationship
• Generalization
– Class derived as the UNION of subclasses
• Aggregation
– Relationships treated as higher level entities
• N-ary relationships
Example
• Sales Clerk’s view: Sales Receipt
• Inventory Clerk’s View: Supply Order
• Inventory Manager’s view: Inventory Report
• Construct an ERD for each view
• Specify the attributes for each entity
• Identify primary and foreign keys
• Revise the logical data model by:
– eliminating many to many relationships
– integrating the views
Example: Sales Receipt
A/C Number Receipt No
Customer Name Date
Address
City State ZIP
Item Code Description Price Quantity Item Total
Sub Total
Tax
Total
Example: Supply Order
Supplier Number Order No
Supplier Name Date
Address
City State ZIP
Item Code Description Quantity
Inventory Report
Item Code Description Price Stock level Reorder point Reorder quantity
ERD for Sales Clerk’s View
1 N
CUSTOMER ORDER
Places
Contains
CUSTOMER ORDER PRODUCT
A/C number Receipt no. Item Code N
Name A/C number Receipt no PRODUCT
St address Sales date Description
City Sub total Price
State Tax Quantity
ZIP Total Item total
ERD for Inventory Clerk’s View
SUPPLIER
1 N
Supplier number SUPPLIER ORDER
Sent to
Name PRODUCT
ORDER M
St address Item Code
City Order no. Order no. Contains
State Description Order date
ZIP Quantity Supplier number N
PRODUCT
Inventory Manager’s view of PRODUCT:
Item code
Description
Price
Inconsistencies?
Stock level
Duplication?
Reorder level
Reorder quantity
Revised ERD
1
CUSTOMER Isa PRODUCT SUPPLIER
1
1 N 1
Places ITEM SOLD Isa Receives
N N N N
SALES 1 N 1
Contains ITEM SUPPLY
ORDER Contains
ORDERED ORDER
Entities and Attributes
CUSTOMER SUPPLIER PRODUCT SALES
A/c number Supplier No Item code ORDER
C_Name S_Name Description Receipt No
C_Address S_Address Cost Price Sales Date
C_City S_City Retail Price A/c number
C_State S_State Stock level Sub total
C_ZIP S_ZIP Reorder level Tax
Reorder quantity Total
ITEM SOLD SUPPLY ORDER ITEM ORDERED
Receipt No Order no. Order No
Item Code Order date Item Code
Quantity Supplier No Quantity
Item total