Documente Academic
Documente Profesional
Documente Cultură
Relational Model
Chapter 3 in Textbook
Database Design
Steps in building a database for an application:
Real-world
domain
Conceptual
model
DBMS data
model
Lilac Safadi
Relational Model
Create
Schema
(DDL)
Load data
(DML)
Relational Model
In the relational model, all data is logically structured
within relations (tables).
Lilac Safadi
Relational Model
STUDENT
StudentNo
Tuples
LName
FName Initial
DOB
GPA
4170010
Al-Saleh
Amal
M.
04-06-78 3.91
4182000
Al-Ghanem Nora
A.
02-12-79 4.20
4182034
Al-Fahad
Laila
A.
01-11-74 4.01
4188134
Saod
Amal
F.
22-04-73 3.01
4189860
Rashed
Rana
I.
30-01-78 2.31
4192134
Al-Fahad
Rania
M.
19-03-79 3.50
Degree
Lilac Safadi
Relational Model
Domains
STUDENT
StudentNo
LName
FName Initial
DOB
GPA
4170010
Al-Saleh
Amal
M.
04-06-78 3.91
4182000
Al-Ghanem Nora
A.
02-12-79 4.20
4182034
Al-Fahad
A.
01-11-74 4.01
Attribute
Laila
Domain Name
Definition
Digits: size 7
LName
Last Name
Character: size 15
FName
First Name
Character: size 15
Initial
Initial
Character: size 3
DOB
Date of Birth
GPA
Lilac Safadi
Relational Model
Properties of Relations
The relation has a name that is distinct from all other
relation names in the relational DB
Each cell of the relation contains exactly single
value
Each attribute has a distinct name
The values of an attribute are all of the same
domain
Each tuple is distinct. There are no duplicate tuples
The order of attributes has no significance
the order of tuples has no significance; theoretically.
Lilac Safadi
Relational Model
Relational Keys
Candidate key (CK) is an attribute, or set of
attributes, that uniquely identifies a tuple, and no
proper subset is a CK within the relation
Primary Key (PK) is the CK that is selected to
identify tuples uniquely within the relation
Foreign Key (FK) is an attribute, or set of attributes,
within one relation that matches the CK of some
relation. Used to represent relationship between
tuples of two relations.
Lilac Safadi
Relational Model
Relational Keys
STUDENT
StudentNo
Primary
Key
LName
FName Initial
DOB
GPA
Dept
4170010
Al-Saleh
Amal
M.
04-06-78 3.91
D001
4182000
Al-Ghanem Nora
A.
02-12-79 4.20
D001
4182034
Al-Fahad
Laila
A.
01-11-74 4.01
D002
4188134
Saod
Amal
F.
22-04-73 3.01
D003
4189860
Rashed
Rana
I.
30-01-78 2.31
D001
Foreign
Key
DEPARTMENT
DeptNo
Department Name
Location
Build # 20
Build # 45
D003 Science
Build # 6
Lilac Safadi
Relational Model
10
DB Relations
Relation schema is a named relation defined by
a set of attributes
If A1, A2, .., An are a set of attributes, then relation
schema R is:
R = (A1, A2, .., An)
Relational schema is a set of relation schemas,
each with a distinct name
If R1, R2, .., Rn are a set of relation schemas, then
relational schema R is:
R= {RLilac
R2, .., Rn}
1, Safadi
11
Relational Model
Relation Schema
STUDENT
StudentNo
LName
FName Initial
DOB
GPA
Dept
4170010
Al-Saleh
Amal
M.
04-06-78 3.91
D001
4182000
Al-Ghanem Nora
A.
02-12-79 4.20
D001
4182034
Al-Fahad
Laila
A.
01-11-74 4.01
D002
4188134
Saod
Amal
F.
22-04-73 3.01
D003
4189860
Rashed
Rana
I.
30-01-78 2.31
D001
Lilac Safadi
Relational Model
12
Relation Schema
DEPARTMENT
DeptNo
Department Name
Location
Build # 20
Build # 45
D003 Science
Build # 6
Lilac Safadi
Relational Model
13
E/R
Relational Model
Entity Type
Relational Model
Lilac Safadi
Relational Model
15
Relational Model
A weak entity type relation must include its key and its
strong entity type PK as a FK. The combination of the two
keys form the PK of the weak entity.
LName
FName
EmpNo
DepNo
FName
DOB
EMPLOYEE
has
DEPENDENT
16
1:1 Relationship
Relational Model
EmpNo
FName
DOB StartD
EndD
EMPLOYEE
(0,1)
Name
BrnNo
manage
(1,1)
BRANCH
17
1:M Relationship
Relational Model
FName
EmpNo
Name
BrnNo
DOB
EMPLOYEE
allocate
BRANCH
18
M:N Relationship
Relational Model
FName
EmpNo
DOB
EMPLOYEE
Name
ProjNo
hours
work-on
PROJECT
19
n-ary Relationship
Relational Model
BizNo
BUSINESS
LawNo
EndD
contract
SupNo
SUPPLIER
Lawyer
20
Composite Attribute
Relational Model
LName
initial
FName
name
DOB
emp_no
EMPLOYEE
EMPLOYEE(EmpNo, Fname, initial, Lname, DOB)
Lilac Safadi
Relational Model
21
MultiValue Attribute
Relational Model
Tel_no
EMPLOYEE
EMPLOYEE(EmpNo, DOB)
TELEPHONE(EmpNo, tel_no)
Lilac Safadi
Relational Model
22
EER
Relational Model
Mandatory/NonDisjoint
Suppose specialization with subclasses (S1, S2, .., Sm} & a
superclass C
Create a relation L to represent C with PK & attributes
Include the unshared attributes for each subclass Si, 1 i m
Lilac Safadi
Relational Model
23
EER
Relational Model
Mandatory/NonDisjoint
Salary
EmpNo
Fname
LName
EMPLOYEE
DOB
o
Typing
Speed
SECRETARY
TECHNICIAN
ENGINEER
EngType
TGrade
EMPLOYEE(EmpNo, Fname, Lname, DOB, Salary,TypingSpeed,TGrade,
EngType, Secretary Flag, Technician Flag, Engineer Flag)
Lilac Safadi
Relational Model
24
EER
Relational Model
Mandatory/Disjoint
Suppose specialization with subclasses (S1, S2, .., Sm} & a
superclass C
Create a relation Li, 1 i m, to represent each combination
of super/subclass
Lilac Safadi
Relational Model
25
EER
Relational Model
Mandatory/Disjoint
Salary
EmpNo
Fname
LName
EMPLOYEE
DOB
d
Typing
Speed
SECRETARY
TECHNICIAN
ENGINEER
EngType
TGrade
SECRETARY(EmpNo, Fname, Lname, DOB, Salary,TypingSpeed)
TECHNICIAN(EmpNo, Fname, Lname, DOB, Salary,Tgrade)
ENGINEER(EmpNo, Fname, Lname, DOB, Salary, EngType)
Lilac Safadi
Relational Model
26
EER
Relational Model
Optional/NonDisjoint
Suppose specialization with subclasses (S1, S2, .., Sm} & a
superclass C
Create a relation L to represent C with PK & attributes
Create a relation Li to represent each subclass Si, 1 i m
Lilac Safadi
Relational Model
27
EER
Relational Model
Optional/NonDisjoint
Salary
EmpNo
Fname
LName
EMPLOYEE
DOB
o
Typing
Speed
SECRETARY
TECHNICIAN
ENGINEER
EngType
TGrade
28
EER
Relational Model
Optional/Disjoint
Suppose specialization with subclasses (S1, S2, .., Sm} & a
superclass C
Create a relation L1 to represent C with PK & attributes
Create a relation L2 to represent all subclasses Si, 1 i m
Lilac Safadi
Relational Model
29
EER
Relational Model
Optional/Disjoint
Salary
EmpNo
Fname
LName
EMPLOYEE
DOB
d
Typing
Speed
SECRETARY
TECHNICIAN
ENGINEER
EngType
TGrade
30
E/R
Relational Model
E/R Model
Relational Model
Entity Type
Relation
FK or relation
Relation & 2 FK
Relation & n FK
Simple attribute
Attribute
Composite attribute
Multivalued attribute
Relation and FK
Value set
Domain
Key attribute
PK
Lilac Safadi
Relational Model
31
Views
Base relation is a named relation corresponding to an
entity in the conceptual schema, whose tuples are
physically stored in the DB
View is a derived relation. Virtual, may not exist, but
dynamically derived from one or more base relations.
The only information about a view that is stored in the
database is its structure.
32
Views
STUDENT_GPA
StudentNo GPA
View
4170010
3.91
4182000
4.20
4182034
4.01
4188134
3.01
STUDENT
StudentNo
Base
Relation
LName
FName Initial
DOB
GPA
Dept
4170010
Al-Saleh
Amal
M.
04-06-78 3.91
D001
4182000
Al-Ghanem Nora
A.
02-12-79 4.20
D001
4182034
Al-Fahad
Laila
A.
01-11-74 4.01
D002
4188134
Saod
Amal
F.
22-04-73 3.01
D003
Lilac Safadi
Relational Model
33
Purpose of Views
Provides security mechanism by hiding parts of the DB
from certain users
Customize data to users needs, so that the same data
can be seen by different users in different ways
Simplify complex operations. It allow you to work with
data from different tables simultaneously.
Supports logical data independence
Lilac Safadi
Relational Model
34
Updating Views
All updates to a base relation should be immediately
reflected in all views that reference that base relation.
All updates to a view should be reflected in the underlying
base relation, under the following rules:
- Updates are allowed through a view defined using a
simple query involving a single base relation & containing
either the PK or a CK of the base relation
- Update are NOT allowed through views involving multiple
base relations
- Updates are not allowed through views involving
aggregation or grouping operations
Lilac Safadi
Relational Model
35
Relational Integrity
Data integrity refers to the validity, consistency,
and accuracy of the data in the database.
Integrity rules are constraints that apply to all
instances of the DB.
Two integrity rules for the relational model:
- Entity integrity
- Referential integrity
Lilac Safadi
Relational Model
36
Relational Integrity
Entity Integrity: Ensures that there are no duplicate
records within the table. In a base relation, no attribute
of a PK can be null
Referential Integrity: If a FK exists in a relation, either
the FK value must match a CK value of some tuple in
its home relation or the FK value must be wholly null.
Enterprise constraints: rules specified by the users
or DBA of the DB based on the ways an organization
perceives and uses its data
(e.g.number of staff working in a branch is at most 20)
Lilac Safadi
Relational Model
37
Relational database
Relation, attribute, tuple, degree, cardinality
Primary Key, Foreign Key
Relation schema, Relational database
schema
Relational Integrity, Entity Integrity,
Referential Integrity, Enterprise Constraints
Views
Lilac Safadi
Relational Model
38