170 likes | 229 Views
Assignment 1. 5. X = {x: x = 5 * n, where n N} Y = {y: y = 7 * n - 2, where n N} Note: set N is the set of all non-negative integers. N = {0,1, 2, 3, 4 . . . } y = 7 * n – 2 = (7 * n) – 2 ≠ 7 * (n – 2). Assignment 1.
E N D
Assignment 1 5. X = {x: x = 5 * n, where n N} Y = {y: y = 7 * n - 2, where n N} Note: set N is the set of all non-negative integers. N = {0,1, 2, 3, 4 . . . } y = 7 * n – 2 = (7 * n) – 2 ≠ 7 * (n – 2)
Assignment 1 5. X = {x: x = 5 * n, where n N} Y = {y: y = 7 * n - 2, where n N} Note: set N is the set of all non-negative integers. 5.1 List the first three elements of each set, starting with the smallest one. N: 0, 1, 2, . . . X: 0, 5, 10, . . . Y: -2, 5, 12, . . . 5.2 Give a one-to-one mapping between the two sets. The formula must not contain n. x = 5 * n n = x / 5 y = 7 * n – 2 y = 7 * (x / 5) - 2
Assignment 2 • Relational Algebra • Which tables? • What operations? • Common attributes? • What result (attributes)? • Syntax (Standard Notations and Symbols)
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) ) Guest.* ( (fromDate <= CurrentDate and toDate >= CurrentDate) and 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)))