Assignment 2 Relational Algebra Which tables? What operations? Common attributes? What result (attributes)? Syntax (Standard Notations and Symbols) Product: X Join:
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) }
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)
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)
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)
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)
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.
b) List all single rooms with a price below £20 per night Room (roomNo, hotelNo, type, price) (type = ‘Single’ and price < 20) (Room)
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) (type = ‘Single’ and price < 20 pounds) (Room) (type = ‘Single’ price < 20) (Room) Incorrect notation!
c) List the name and addresses of all guests Guest (guestNo, guestName, guestAddress) guestName, guestAddress (Guest) One table only! guestAddress: (street, city, state, zipcode) composite attribute
c) List the name and addresses of all guests Guest (guestNo, guestName, guestAddress) guestName, guestAddress (Guest) guestName, guestAddress (Guest Booking Hotel ) Don’t need Joins!
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))
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))
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)))
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
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