Comp1121 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

COMP1121

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

• Components of a data model


– A structural part – set of rules
– A manipulative part – operations allowed on data
– A set of integrity constraints

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

• Relations for Influencer Profile Management


System
• What data do we want to store?
– Name
– Social media app, handle, follower count
– Others?

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

Tomorrow, we look at Relational Algebra

17
Follow-up work
• Complete required reading:
– Connolly & Begg: Chapter 4

• Reading for next lecture:


– Connolly & Begg: Chapter 5: 5.1

18

You might also like