Comp1121 3
Comp1121 3
Comp1121 3
Databases
3: Relational Model
Our journey so far ...
Database
Environment Relational Relational
Introduction & Algebra
Model
Architecture
SQL
Entity
Normalisation Relationship
Modelling
Database
Designs
Ethics of
Security & Transaction Using
Administration Management Databases
2
Learning objectives
• To describe the properties of database relations.
• To explain entity integrity and referential
integrity.
• To explain the purpose and advantages of views.
3
Relational Data Model
4
Terminology
5
Attribute Domains
6
Alternative Terminology
7
Database Relations
• A relation schema
• R = {A1:D1, A2:D2, ..., An:Dn}
• Branch = {branchNo:BranchNumbers,
street:StreetNames, city:CityNames,
postcode:Postcodes}
• Convention: Branch(branchNo, street, city, postcode)
• An instance/ tuple: {(branchNo:B005, street:22 Deer
Rd, city:London, postcode:SW1 4EH)} or {(B005, 22
Deer Rd, London, SW1 4EH)}
• A database schema?
• R = {R1, R2, ...Rn}
8
Let’s brainstorm
9
Properties of Relations
• Relation name is DISTINCT.
• Each cell contains exactly ONE value.
• Each attribute has a DISTINCT name.
• Values of an attribute from the SAME DOMAIN,
• Each tuple is DISTINCT.
• Order of attributes has NO significance.
• Order of tuples has NO significance,
theoretically.
10
Relational Keys
• Superkey
• Candidate key
• Primary key
• Foreign key
11
Relational database schemas
12
Integrity Constraints
• Entity Integrity
• Referential
Integrity
• Multiplicity
constraints
• General
constraints
13
Views
• A virtual relation that does not necessarily
actually exist in the database but is
produced upon request, at time of request.
• Dynamic result of one or more relational
operations operating on base relations to
produce another relation.
• Branch(branchNo, street, city, postcode)
– Views?
– example
14
Purpose of Views
• Provides powerful and flexible security mechanism by
hiding parts of database from certain users.
• Permits users to access data in a customized way, so
that same data can be seen by different users in
different ways, at same time.
• Can simplify complex operations on base relations.
15
Updating Views
• All updates to a base relation should be immediately
reflected in all views that reference that base relation.
• If view is updated, underlying base relation should
reflect change.
• There are restrictions on types of modifications that
can be made through views:
– Updates are allowed if query involves a single base relation
and contains a candidate key of base relation.
– Updates are not allowed involving multiple base relations.
– Updates are not allowed involving aggregation or grouping
operations.
16
Summary
• Terminology of the relational model
• Properties of relations
• Relational keys
• Integrity constraints of data models
• Views
17
Follow-up work
• Complete required reading:
– Connolly & Begg: Chapter 4
18