Docsity

Relational Databases-Lecture 10 Slides-Computer Science, Slides of Relational Database Management Systems (RDBMS)

Toggle sidebar
bg1
Relational Databases - Comp2400 / Comp6240
Lecture 13: Relational Algebra
SQL meets Maths
With only minor additions and adaptations, yesterday’s bit of
pure maths becomes a useful theory of databases.
The plan for todays lectures is to
start with a simple SQL query
develop the maths until we can express that same query in
relational algebra
along the way, see what algebraic rules we can use to
manipulate it
This material is from [E&N §6.1 - 6.5, §8.4]
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39

Partial preview of the text

Download Relational Databases-Lecture 10 Slides-Computer Science and more Slides Relational Database Management Systems (RDBMS) in PDF only on Docsity!

Relational Databases - Comp2400 / Comp

Lecture 13: Relational Algebra

SQL meets Maths

With only minor additions and adaptations, yesterday’s bit of

pure maths becomes a useful theory of databases.

The plan for todays lectures is to

start with a simple SQL query

develop the maths until we can express that same query in

relational algebra

along the way, see what algebraic rules we can use to

manipulate it

This material is from [E&N §6.1 - 6.5, §8.4]

Announcements

Assignment 1 is on the course web page, due 5pm, Friday

5th September. No marks for late submissions.

Announcements

Assignment 1 is on the course web page, due 5pm, Friday

5th September. No marks for late submissions.

both paper and electronic submission required

please read assignment sheet carefully and understand

what is required

Announcements

Assignment 1 is on the course web page, due 5pm, Friday

5th September. No marks for late submissions.

both paper and electronic submission required

please read assignment sheet carefully and understand

what is required

see the “pick and pack” example

Announcements

Assignment 1 is on the course web page, due 5pm, Friday

5th September. No marks for late submissions.

both paper and electronic submission required

please read assignment sheet carefully and understand

what is required

see the “pick and pack” example

Mid-semester exam is on Wednesday 10th September,

starting 12:50, for one hour, at Melville Hall.

last years mid-test paper is on the course web page

An Example Query

Our toy organisation wants to review employees in finance and

administration departments.

(Database from Lab 1)

An Example Query

Our toy organisation wants to review employees in finance and

administration departments.

(Database from Lab 1)

SELECT enumber,fname,lname,dname

FROM employee,department

WHERE (dname=’Administration’ OR dname=’Finance’)

AND dnumber=dno;

We will express this query as mathematics.

Set Size

We write | A | for the number of elements in a set A.

Set Size

We write | A | for the number of elements in a set A.

Here’s a few cute facts about set size.

| A × B | = | A | × | B |

i ∈ I Ai

i ∈ I | Ai |

Set Size

We write | A | for the number of elements in a set A.

Here’s a few cute facts about set size.

| A × B | = | A | × | B |

i ∈ I Ai

i ∈ I | Ai |

ie | • | is a product homomorphism

Set Size

We write | A | for the number of elements in a set A.

Here’s a few cute facts about set size.

| A × B | = | A | × | B |

i ∈ I Ai

i ∈ I | Ai |

ie | • | is a product homomorphism

| A ∪ B | ≤ | A | + | B |

| A ∩ B | ≤ | A | and | A ∩ B | ≤ | B |

Set Size

We write | A | for the number of elements in a set A.

Here’s a few cute facts about set size.

| A × B | = | A | × | B |

i ∈ I Ai

i ∈ I | Ai |

ie | • | is a product homomorphism

| A ∪ B | ≤ | A | + | B |

| A ∩ B | ≤ | A | and | A ∩ B | ≤ | B |

| A − B | ≥ | A | − | B |

Projections

Recall that an indexed set is a set whose elements have

names.

We can use those names to extract the elements.

Projections

Recall that an indexed set is a set whose elements have

names.

We can use those names to extract the elements.

π city { city = Paris , custID = 11 } = { city = Paris }

π 1 , 3 ( 2 , 11 , 42 ) = ( 2 , 42 )