Chapter 4 Logical Database Design and The Relational Model Part
Chapter 4 Logical Database Design and The Relational Model Part
Relational Model
part 1
1
Objectives
Relational Model
– Requirement
– Primary and foreign keys
– Integrity constraints
2
Systems Development Life Cycle
Logical
Logical Design
Design
Physical Design
Database activity–
logical database design Implementation
(transactions, forms, displays, views,
data integrity and security) Maintenance
Typically map ER diagram to tables
3
Relation
• Definition: A relation is a named, two-dimensional table of
data
• Table consists of rows (records) and columns (attribute or
field)
• Requirements for a table to qualify as a relation:
– It must have a unique name
– Every attribute value must be atomic (not multivalued, not composite)
– Every row must be unique (can’t have two rows with exactly the same
values for all their fields)
– Attributes (columns) in tables must have unique names
– The order of the columns must be irrelevant
– The order of the rows must be irrelevant
4
Correspondence with E-R Model
Customer Orders
Orders.cust-id are just copies of cust-id in customer table who placed the order
There is no need to copy more information about customer in order table because
cust-id uniquely identifies a customer (so other information about that customer
can be located in customer relation given the cust-id)
8
Key Fields (cont.)
9
primary and foreign keys for four relations
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
10
Integrity Constraints
• Domain Constraints
– Allowable values for an attribute.
• Entity Integrity
– No primary key attribute may be null. All
primary key fields MUST have data
11
Domain definitions enforce domain integrity constraints
12
Referential integrity
13
Referential integrity (cont.)
• Referential Integrity example
14
Referential integrity
Referential
integrity
constraints are
drawn via arrows
from dependent to
parent table
15
SQL table definitions to show referential integrity implementation
Referential
integrity
constraints are
implemented with
foreign key to
primary key
references
16
Questions
• Can foreign key be NULL? YES, it can be NULL
– E.g. CID in orders table is null
• Can foreign key points to an non existing row in the primary
table? NO, it can't point to a non-existing primary key
– E.g. CID in orders table equals a CID that can not be found
in Customer table
CID Cust-name OID Order-date CID
1 Jones 1 ’05/1/1’ 1
2 Smith 2 ‘05/2/1’ 1