Database Management Systems Week 5
Database Management Systems Week 5
2
Deletion
▪ A delete request is expressed similarly to a query, except instead
of displaying tuples to the user, the selected tuples are removed
from the database.
▪ Can delete only whole tuples; cannot delete values on only
particular attributes
▪ A deletion is expressed in relational algebra by:
rr–E
where r is a relation and E is a relational algebra query.
3
Quick Review: Set Difference Operation
▪ Notation r – s
▪ Defined as:
r – s = {t | t r and t s}
▪ For r – s to be valid:
1. r, s must have the same arity
2. The attribute domains must be compatible
4
Quick Review: Set Difference Operation
▪ Relations r, s:
A B A B
1 2
2 s
1
r
▪ r – s:
A B
1
1
5
Banking Enterprise Schema Diagram
6
6
Deletion Examples
▪ Delete all account records in the Perryridge branch.
account account – branch_name = “Perryridge” (account )
7
Insertion
8
Quick Review: Set Union Operation
▪ Notation: r s
▪ Defined as:
r s = {t | t r or t s}
▪ For r s to be valid:
1. r, s must have the same arity
2. The attribute domains must be compatible
9
Quick Review: Set Union Operation
▪ Relations r, s: A B A B
1 3
2 s
1
r
A B
▪ r s: 1
2
1
3
10
Insertion Examples
▪ Insert information in the database specifying that Smith has $1200 in
account A-973 at the Perryridge branch.
11
Updating
▪ Each Fi is either
▪ the I th attribute of r, if the I th attribute is not updated, or,
▪ if the attribute is to be updated Fi is an expression, involving only
constants and the attributes of r, which gives the new value for the
attribute
12
Update Examples
13
Update Examples
14
Exercises
15
1) Find the names of sailors who’ve reserved boat #103
πsname(temp2)
▪ Can identify all red or green boats, then find sailors who’ve reserved one
of these boats:
▪ Then find the intersection (note that sid is a key for Sailor relation).
πsname(TempSids ⋈ Sailor)
πsname(TempSids ⋈ Sailor)