Database Design Using The Relational Model: Lecture Notes Prepared by Prof. Melody Angelique C. Rivera
Database Design Using The Relational Model: Lecture Notes Prepared by Prof. Melody Angelique C. Rivera
Three-step Process in
Designing Databases
Functional Analysis
identifies
Three-step Process in
Designing Databases
Data Analysis
Three
(3) Phases
Conceptual Design
Logical Design
Physical Design
Physical Implementation
the
Business Rule:
A statement
Declarative
Precise
Atomic
Consistent
Expressible
Distinct
Business-oriented
names should:
Example: Customer
names (continued)
Be readable
Be composed of words taken from an approved list
Repeatable
Definitions
Fact
An association between two or more terms
Example of a fact that is a definition (the defined
term is underlined): A course is a module of
instruction in a particular subject area
10
Data Analysis:
Phase 1
Conceptual Database Design
12
Entity-Relationship Model
(ER Model)
a popular conceptual data model
there are several variations but there is
one feature that is common to all -- all
data may be represented using any one of
the following major constructs:
ENTITY
ATTRIBUTE
RELATIONSHIP
13
Entity-Relationship Model
(ER Model) (continued)
ENTITY
an
ATTRIBUTE
a
Entity-Relationship Model
(ER Model) (continued)
RELATIONSHIP
an
15
Conceptual
Database Design
The Entity-Relationship
Diagram (ERD)
entity
attribute
relationship
17
ERD Example
attributes
DateBorrowed
MemberNo
MEMBER
MemLast Name
BookNo
borrows
BOOK
MemAddress
BookTitle
MemFirstName
BookAuthor
relationship
entities
18
The Entity
19
Entity
Entity Instance
A single
The Attribute
21
Attribute
Types of Attributes
Simple
Composite
Single-Valued
Multivalued
Stored
Derived
Required
Optional
22
Simple Attribute
An attribute that cannot be broken down
into smaller components
Example: STUDENT entity
StudentID
StudentLastName
StudentDegree
STUDENT
StudentID
StudentLastName
StudentDegree
23
Composite Attribute
An attribute that can be broken down into
component parts
Component attributes may appear above
or below the composite attribute on an ER diagram
The decision whether to subdivide an
attribute into its component parts depends
on whether user will need to refer to those
individual components
24
Number
STUDENT
StudentID
Address
Street_Address
City
ZipCode
Province
25
Required Attribute
An attribute that must have a value for
each entity instance
Example: STUDENT entity
StudentID
StudentLastName
StudentFirstName
StudentDegree
26
Optional Attribute
An attribute that may not have a value for
every entity instance
Example: STUDENT entity
StudentMajor
StudentHomePhone
27
Data Type
Entity Instance
Entity Instance
StudentID
Char (12)
2007-1-01254
2007-2-00349
StudentLastName
Char (20)
Pineda
Gonzalez
StudentFirstName
Char (30)
Katherine
Bernardo
StudentDegree
Char (10)
BSMT
BBA
StudentMajor
Char (10)
Management
StudentHomePhone
Char (11)
032-4125621
28
Single-Valued Attribute
An attribute that has only one value
Example: STUDENT entity
StudentGender
StudentCivilStatus
29
Multivalued Attribute
An attribute that may take on more than
one value for a given entity instance
Example: EMPLOYEE entity
EmpSkill
Multivalued vs Single-valued
Attribute Example
EmpID
EmpName
EMPLOYEE
EmpDateEmployed
EmpSkill
EmpGender
Multivalued Attribute
Single-valued Attributes
31
Transforming (Exploding)
Multivalued Attributes
Dorm_No
Dorm_Name
Manager
DORMITORY
Location
Rooms
Original Diagram
Multivalued Attribute
32
Transforming (Exploding)
Multivalued Attributes (continued)
Dorm_No
Dorm_Name
DORMITORY
Location
Manager
Start_Rent
has
Room_No
Capacity
ROOM
End_Rent
Room_Name
Course_Title
COURSE
Prerequisite
Original Diagram
34
Course_Title
COURSE
Transformation of the
Multivalued Attribute
Is_A_Prerequisite_for
35
Stored Attribute
An attribute that gets its value directly from
an input device (e.g. keyboard)
Example: STUDENT entity
StudentID
StudentLastName
StudentFirstName
StudentDegree
36
Derived Attribute
An attribute whose values can be
calculated from related attribute values
(and possibly data not in the database)
Example: EMPLOYEE entity
EmpYearsEmployed
EmpName
EMPLOYEE
EmpYearsEmployed
EmpDateEmployed
EmpSkill
EmpPhoneNo
Derived Attribute
38
Key Attribute
Identifier
An
Identifier Example
EmpID
EmpName
EMPLOYEE
Identifier or
Primary key
(Simple key
attribute)
EmpDateEmployed
EmpSkill
EmpYearsEmployed
40
Identifier Example
Year
Semester
StudentNo
StudentID
STUDENT
StudentLastName
StudentCourse
41
The Relationship
42
Relationship Names
A verb
Present tense
Examples:
Manages
(or Is_Managed)
Receives (or Is_Received)
Enrolls (or Is_Enrolled)
Stays / Occupies (or Is_Occupied)
Marries (or Is_Married)
43
UNARY RELATIONSHIP
- Only one entity
is involved in the
relationship
EMPLOYEE
supervises
EMPLOYEE
manages
DEPARTMENT
45
VENDOR
PART
ships
WAREHOUSE
VENDOR
PART
ships
WAREHOUSE
TRANSPORTATION
47
PERSON
CAR
registers
V_code
V_title
M_name
MEMBER
borrows
VCD
V_avail
Date_due
49
Cardinalities in Relationships
50
Cardinalities in Relationships
(continued)
Many-to-many (M:N)
we
One-to-many (1:M)
one
Mandatory One
Mandatory One or Many
Optional Zero or One
Minimum
Cardinality
Maximum
Cardinality
- the greatest number of
instances allowed to
participate in a
relationship
53
owns
CAR
1:1
Mandatory One
54
borrows
VCD
1:M
55
takes
COURSE
M:N
Mandatory
One or Many
An instance of a student takes one or more courses.
An instance of a course is taken by one or more students.
56
Is
assigned
to
PROJECT
Optional Zero, One
or Many
58
Existence Dependency
Occurs
has
HISTORY
59
PatientName
PatientNo
PatientNo
PATIENT
HistoryNo
HISTORY
has
Diagnosis
ConsultationDate
60
double rectangle
61
62
Two Approaches in
Conceptual Design
top down
identify
the entity
identify the attributes
identify the relationship
bottom-up
entity,
Top-down Example
in a video shop
entities
MemName
MemAddr
MEDIA
MediaNo
MEMBER
MemNo
Main_Actor
MediaTitle
65
Bottom-up Example
list given:
s_name
code
location
student
room
enrolls
course
address
yr_level
teacher
time
title
the ERD:
s_name
STUDENT
teacher
code
address
time
COURSE
has
location
yr_level
room
title
66