Relational Model: Lecture - 3
Relational Model: Lecture - 3
LECTURE - 3
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Relational Model Terminology
3
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Relational Model Terminology
5
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Instances of Branch & Staff Relations
6
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Examples of Attribute Domains
7
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Alternative Terminologies
8
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Mathematical Definition of Relation
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Mathematical Definition of Relation
11
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Mathematical Definition of Relation
12
Relation schema
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Relation
14
Relation Schema
{branchNo:D1, street:D2, city:D3, postcode:D4}
Relation/relation instance
{branchNo:B005, street:22 Deer Rd, city:London, postcode:SW1 4EH}
{branchNo:B007, street:16 Argyll St, city:Aberdeen, postcode:AB2 3SU}
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Database Relations
16
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Properties of Relations
17
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Relational Keys
19
Superkey
An attribute, or set of attributes, that uniquely
identifies a tuple within a relation.
Candidate Key
Superkey (K) such that no proper subset is a superkey
within the relation.
In each tuple of R, values of K uniquely identify that
tuple (uniqueness).
No proper subset of K has the uniqueness property
(irreducibility).
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Relational Keys
20
Branch
Candidate keys
Branch branchNo,
postcode
Notes
Relation instance Staff
cannot be used to
prove a candidate key
Candidate key
identification
Know the real world
meaning of attributes
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Relational Keys
21
Primary Key
Candidate key selected to identify tuples uniquely within
relation.
Alternate Keys
Candidate keys that are not selected to be primary key.
Foreign Key
Attribute, or set of attributes, within one relation that
matches candidate key of some (possibly same) relation.
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Representing Relational DB Schemas
22
Example:
Branch(branchNo, street, city, postcode)
Staff(staffNo, fName, lName, position, sex, DOB,
salary, branchNo)
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Integrity Constraints
23
Null
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Integrity Constraints
24
Entity Integrity
In a base relation, no attribute of a primary key can be
null.
Base relation corresponds to an entity in a conceptual
schema.
Referential Integrity
If foreign key exists in a relation, either foreign key
value must match a candidate key value of some tuple
in its home relation or foreign key value must be
wholly null.
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Integrity Constraints
25
General Constraints
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Views
26
Base Relation
Named relation corresponding to an entity in
conceptual schema, whose tuples are physically stored
in database.
View
Dynamic result of one or more relational operations
operating on base relations to produce another relation.
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Views
27
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Purpose of Views
28
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Kuis-1
29
Rumah sakit
Department store
Universitas
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Kuis-2
30
Restoran
Minimarket
Perpustakaan
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Relational Calculus
31
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Relational Calculus
32
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Tuple Relational Calculus
34
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Tuple Relational Calculus - Example
35
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Tuple Relational Calculus
36
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Tuple Relational Calculus
37
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Tuple Relational Calculus
38
Means: there exists a Branch tuple with same branchNo as the branchNo of
the current Staff tuple, S, and is located in London’
Branch Staff
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Tuple Relational Calculus
39
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Tuple Relational Calculus
40
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Example - Tuple Relational Calculus
42
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Example - Tuple Relational Calculus
43
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Latihan
44
PropertyForRent Branch
prope street city post rent owner staff branch branch street city postcode
rtyNo code No No No No
PA14 16 Holdead Aberden AB7 650 CO46 SA9 B007 B005 22 Deer London SW1 4EH
5SU Rd
PL94 6 Agryll St London NW2 400 CO87 SL41 B005 B007 16 Agryll Aberdeen AB2 3SU
St
PG4 6 Lawrence Glasgow G11 350 CO40 B003
B003 163 Glasgow G11 9QX
ST 9QX
Main ST
PG36 2 Manor Rd Glasgow G32 375 CO93 SG37 B003
B004 32 Bristol BS99 iNZ
4QX
Manse
PG21 18 Dale Rd Glasgow G12 600 CO87 SG37 B003 Rd
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Jawaban
45
PropertyForRent Branch
prope street city post rent owner staff branch branch street city postcode
rtyNo code No No No No
PA14 16 Holdead Aberden AB7 650 CO46 SA9 B007 B005 22 Deer London SW1 4EH
5SU Rd
PL94 6 Agryll St London NW2 400 CO87 SL41 B005 B007 16 Agryll Aberdeen AB2 3SU
St
PG4 6 Lawrence Glasgow G11 350 CO40 B003
B003 163 Glasgow G11 9QX
ST 9QX
Main ST
PG36 2 Manor Rd Glasgow G32 375 CO93 SG37 B003
B004 32 Bristol BS99 iNZ
4QX
Manse
PG21 18 Dale Rd Glasgow G12 600 CO87 SG37 B003 Rd
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Domain Relational Calculus
46
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Example - Domain Relational Calculus
47
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Example - Domain Relational Calculus
48
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Example - Domain Relational Calculus
49
{fN, lN | ($sN)
(Staff(sN,fN,lN,posn,sex,DOB,sal,bN)
(~($sN1) (PropertyForRent(pN, st, cty, pc, typ,
rms, rnt, oN, sN1, bN1) Ù (sN=sN1))))}
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)
Example - Domain Relational Calculus
50
Dr. Said Mirza Pahlevi, M.Eng. Sekolah Tinggi Ilmu Statistik (STIS)