Download presentation
Presentation is loading. Please wait.
1
Assignment 2
2
I a) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1)
S = {(x, a, 1), (y, b, 1), (z, a, 4)} A1, B2 (A1 < 4 and B1 x (S)) = A1, B2 ( { (y, b, 1) } ) = { (1, b) }
3
I b) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1)
S = {(x, a, 1), (y, b, 1), (z, a, 4)} A2, B1 ( R.A1 > S.A1 ( R S)) = { (3, x), (3, y), (8, x), (8, y), (9, x), (9, y)} R S (1, 2, x, a, 1) (1, 2, y, b, 1) (1, 2, z, a, 4) (4, 3, x, a, 1) (4, 3, y, b, 1) (4, 3, z, a, 4) (2, 9, x, a, 1) (2, 9, y, b, 1) (2, 9, z, a, 4) (3, 8, x, a, 1) (3, 8, y, b, 1) (3, 8, z, a, 4) R.A1 > S.A1 ( R S) (4, 3, x, a, 1) (4, 3, y, b, 1) (2, 9, x, a, 1) (2, 9, y, b, 1) (3, 8, x, a, 1) (3, 8, y, b, 1)
4
I c) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1)
S = {(x, a, 1), (y, b, 1), (z, a, 4)} R S = { (1, 2, x, a), (1, 2, y, b), (4, 3, z, a)} R S (1, 2, x, a, 1) (1, 2, y, b, 1) (1, 2, z, a, 4) (4, 3, x, a, 1) (4, 3, y, b, 1) (4, 3, z, a, 4) (2, 9, x, a, 1) (2, 9, y, b, 1) (2, 9, z, a, 4) (3, 8, x, a, 1) (3, 8, y, b, 1) (3, 8, z, a, 4) R.A1 = S.A1 ( R S) (1, 2, x, a, 1) (1, 2, y, b, 1) (4, 3, z, a, 4)
5
I d) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1)
S = {(x, a, 1), (y, b, 1), (z, a, 4)} A2, B1, B2, S.A1 (R S) = { (2, x, a, 1), (2, y, b, 1), (3, z, a, 4)} R S (1, 2, x, a, 1) (4, 3, x, a, 1) (2, 9, x, a, 1) (3, 8, x, a, 1) (1, 2, y, b, 1) (4, 3, y, b, 1) (2, 9, y, b, 1) (3, 8, y, b, 1) (1, 2, z, a, 4) (4, 3, z, a, 4) (2, 9, z, a, 4) (3, 8, z, a, 4) R S (1, 2, x, a, 1) (1, 2, y, b, 1) (4, 3, z, a, 4)
6
I e) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1)
S = {(x, a, 1), (y, b, 1), (z, a, 4)} R S = { (1, 2, x, a), (1, 2, y, b), (4, 3, z, a), (2, 9, null, null), (3, 8, null, null)} R S (1, 2, x, a, 1) (1, 2, y, b, 1) (1, 2, z, a, 4) (4, 3, x, a, 1) (4, 3, y, b, 1) (4, 3, z, a, 4) (2, 9, x, a, 1) (2, 9, y, b, 1) (2, 9, z, a, 4) (3, 8, x, a, 1) (3, 8, y, b, 1) (3, 8, z, a, 4) R S (1, 2, x, a, 1) (1, 2, y, b, 1) (4, 3, z, a, 4) (2, 9, null, null, null) (3, 8, null, null, null)
7
Assignment 2: II Relational Algebra Which tables?
Join, Out Join, or No Join Common attributes for Join and Out Join? Which records (selection)? What attributes (projection)? Syntax (Standard Notations and Symbols) Product: X Join:
8
II (a) List all hotels Hotel (hotelNo, hotelName, city) * (Hotel)
Use H for Hotel * (H) hotelNo, hotelName, city (Hotel) hotelNo (Hotel) Incorrect! All attributes when not specified.
9
b) List all single rooms with a price below $20 per night
Room (roomNo, hotelNo, type, price) (type = ‘Single’ and price < 20) (Room)
10
b) List all single rooms with a price below $20 per night
* ( (type = ‘Single’ and price < 20) (Room) ) Projection is NOT Needed! (type = Single and price < 20) (Room) (type = “Single” and price < 20) (Room) (type = ‘Single’ and price < $20) (Room)
11
c) List the name and addresses of all guests
Guest (guestNo, guestName, guestAddress) guestName, guestAddress (Guest)
12
d) List the price and type of all rooms at the Grosvenor Hotel
Room (RoomNo, HotelNo, Type, Price) Hotel (HotelNo, hotelName) price, type ( hotelName = ‘Grosvenor’ (Room Hotel)) Common attribute: HotelNo price, type (Room (hotelName = ‘Grosvenor’) (Hotel)) Incorrect! It’s the same as the following: price, type ((hotelName = ‘Grosvenor’) (Room Hotel))
13
e) List all guests currently staying at the Grosvenor Hotel
Guest (guestNo, guestName, guestAddress) Hotel (hotelNo, hotelName) Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) Guest.* ( (fromDate <= CurrentDate and toDate >= CurrentDate) and hotelName = ‘Grosvenor’ (Guest Booking Hotel))
14
e) List all guests currently staying at the Grosvenor Hotel
(fromDate <= CurrentDate and toDate >= CurrentDate) and hotelName = ‘Grosvenor’ (Guest Booking Hotel)) Guest.* (Guest ( fromDate <= CurrentDate and toDate >= CurrentDate Booking ) ( hotelName = ‘Grosvenor’ Hotel) )
15
e) List all guests currently staying at the Grosvenor Hotel
Guest (guestNo, guestName, guestAddress) Hotel (hotelNo, hotelName) Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) What is the common attribute between Guest and Hotel? Guest.* ( (fromDate <= CurrentDate and toDate >= CurrentDate) and hotelName = ‘Grosvenor’ (Guest Hotel Booking) ) hotelName = ‘Grosvenor’ (Guest (Hotel Booking)))
16
f) List the details of all rooms at the Grosvenor Hotel, including the name of the guest staying in the room if the room is occupied Room Guest Room.*, guestName (hotelName = ‘Grosvenor’ and fromDate <= CurrentDate and CurrentDate <= toDate) ((Room Hotel) (Booking Guest)) Not correct! Room.*, guestName ( ( hotelName = ‘Grosvenor’ (Room Hotel) ) ( (fromDate <= CurrentDate and CurrentDate <= toDate) (Booking Guest)) ) A room without current booking will join a guest who booked the room before The room will be removed by the selection outside the outer join
17
Ctrl+G: 8. 5/10 Ctrl+I: Incorrect answer: -0
Ctrl+G: 8.5/10 Ctrl+I: Incorrect answer: -0.5 Ctrl+S: Incorrect style: -0.5 Ctrl+T: Missing table(s): -0.5 Ctrl+N: Missing name: -1 Ctrl+N: Incorrect file name: -1
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.