DB1 Lecture3
DB1 Lecture3
(DBMS) – (1)
Code: INF311
Lecture 3
In this Lecture
Data Models
Relational Model
Structure Part
– Consisting of set of rules according to which
databases can be constructed.
Manipulative Part
– Define the types of operation that are
allowed on the data.
To represent data.
Semantic
Functional
Types of Data Models II
Relational Model
Relational
#fields = degree
Example of a Relation
attributes
(or columns)
tuples
(or rows)
--------
---------
---------
Domain
Relational model Aspects
Data structure
Data manipulation
– Relational Algebra
– Relational Calculus
Data integrity
Relational Data structure
attribute types
entity types
relationship types
FLIGHT-SCHEDULE DEPT-AIRPORT
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
16
Data structure terminology
A B A UNION B
X Y X Y X Y
x1 y1 x2 y2 x1 y1
x2 y2 x4 y4 x2 y2
x3 y3 x3 y3
x4 y4
Example - Union
List all cities where there is either a branch office
or a property for rent.
city(Branch) city(PropertyForRent)
Set Difference
A B A MINUS B
X Y X Y X Y
x1 y1 x1 y1
x2 y2
x2 y2 x3 y3
x4 y4
x3 y3
Example - Set Difference
city(Branch) – city(PropertyForRent)
Intersection
A INTERSECT B
A B
X Y X Y
X Y
x2 y2 x2 y2
x1 y1
x4 y4
x2 y2
x3 y3
Example - Intersection
city(Branch) city(PropertyForRent)
Cartesian product
V W X Y Z
v1 w1 x1 y1 z1
v2 w2 x2 y2 z2
v3 w3
A TIMES B
V W X Y Z
v1 w1 x1 y1 z1
v1 w1 x2 y2 z2
v2 w2 x1 y1 z1
v2 w2 x2 y2 z2
v3 w3 x1 y1 z1
v3 w3 x2 y2 z2
Example - Cartesian product
List the names and comments of all clients who have
viewed a property for rent.
(clientNo, fName, lName(Client)) X (clientNo, propertyNo, comment (Viewing))
Join Operations
Creates a new relation from all combinations of
rows satisfying the join condition
A join B where W = Z
A B
V W X Y Z
v1 wz1 x1 y1 wz1
v2 wz2 x2 y2 wz3
v3 wz3
A EQUIJOIN B
V W X Y Z
v1 wz1 x1 y1 wz1
v3 wz3 x2 y2 wz3
Join Operations
Join is a derivative of Cartesian product.
A B
X Y Y
x1 y1 y1
x1 y2 y2
x1 y3
x2 y1
x2 y3
A DIVIDE B
x1
Example - Division
43
Referential Integrity
The referential integrity key applies to Foreign Keys
44
Next Lecture
ER diagram
SQL
– DDL
– DML
– DCL