Databases (HT2014)

Some comments on the lecture slides

LectureSlideComments
24 A key is shown on the next slide. Note, this is not necessarily the only key.
25 Problems with this approach are mentioned on the following slide.
215 Course(code, name, teacher)
219 See next slide.
225 An extra attribute is now added to relation LecturesIn: #times
228 Entity Weekday gives: Weekdays(day)
Relation LecturesIn becomes: LecturesIn(code, name, day)
With one extra reference: day → Weekdays.day
234 A many-to-exactly-one relationship does not require a relationship relation when we map to the relational model. The relationship information can go into the entity relation of the entity on the "many" side of the relationship. In this case, this would give:
Rooms(name, #seats)
Course(code, name, teacher,room)
     room → Rooms.name
235 These two alternative approaches are discussed on slide 37.
246 Courses(code, name)
Rooms(name, #seats)
GivenCourses(course, period, teacher)
     course → Courses.code
LecturesIn(course, period, room)
     (course, period) → GivenCourses.(course, period)
     room → Rooms.name
35 For this slide, and the two that follow, just follow the recipes on the previous slide.
Rooms(name, #seats)
ComputerRooms(name, #computers)
     name → Rooms.name
36 Rooms(name, #seats, #computers)
37 Rooms(name, #seats)
ComputerRooms(name, #seats, #computers)
43 "LHS" = "left-hand side"
"RHS" = "right-hand side"
See update anomaly in lecture 2.
44 The result of decomposing is shown on the next slide.
47 "w.r.t." = "with respect to"
411 The natural join of the two relations in the middle of the slide is a relation with four rows.
513 See the next two slides.
420 Consider the following data:
TDA3572GK
TDA3573AR
TDA3574GK
There is no violation of 3NF, but the table does contain redundancy. In particular, there is no need to repeat the same course code in every row with the same teacher.
2248 The relation on the right is not in fourth normal form.
526 Deletes all rows from relation Courses.
542 The result relation has two rows - the rows of relation Givencourses that satisfy the selection condition.
544
courseteacher
TDA357Niklas Broberg
TDA357Rogardt Heldal
551 σ teacher="Niklas Broberg" ( Courses x GivenCourses )
555
codenamecourseperiodteacher
TDA357DatabasesTDA3572Niklas Broberg
TDA357DatabasesTDA3574Rogardt Heldal
TIN090AlgorithmsTIN0901Devdatt Dubhashi
557
codenameperiodteacher
TDA357Databases2Niklas Broberg
TDA357Databases4Rogardt Heldal
TIN090Algorithms1Devdatt Dubhashi
565 The SQL statement will give a result with three rows:
A
1
5
1
Assuming that relational algebra is set-based (as in section 2.4 iof the textbook), the relational algebra expression will only have two rows:
A
1
5
But see the discussion of relational operations on bags in section 5.1 of the textbook.
63 Find all teachers who have lectures on Mondays in period 2.
The SQL formulation on this slide is to illustrate a subquery. There are other ways to express this query in SQL.
610 Find all lectures that are scheduled in rooms with too few seats.
614 Find days in period 2 when course TDA357 has lectures in room VR.
650 SELECT teacher, AVG(nrSt)
FROM GivenCourses
GROUP BY teacher

γ teacher, AVG(nrSt) ( GivenCourses )
86 SET NULL is not a possible policy for either of the modifications affecting GivenCourses.(course, period), since these are key attributes in relation Lectures, and so cannot have null values. The CASCADE policy seems reasonable if a row is deleted from GivenCourses, or if a room name in Rooms is changed. If a row in GivenCourses is updated, it might seem reasonable to CASCADE the update if it is simply updating the course code, but we might not want a change or period to cascade (i.e. we might not want to automatically reschedule all lectures for the same times and rooms in the new period), so it could be better to REJECT updates to the referenced row. If a row is deleted from the Rooms relation, it seems reasonable to SET NULL the room or lectures scheduled for the deleted room. Or we could consider to REJECT such modifications (until all affected lectures have first been relocated to other rooms). Cancelling lectures (i.e. cascading) just because a particular room is no longer available seems an extreme step to take.
828 "RAISE_USE_ERROR" should be "RAISE_APPLICATION_ERROR"

Last Modified: 1 December 2014 by Graham Kemp