Download presentation
Presentation is loading. Please wait.
1
CS 3630 Database Design and Implementation
2
DreamHome Branch (branchNo, street, city, state, zipcode, phone1, phone2, phone3) Staff (staffNo, firstName, lastName, position, address, DOB, salary, branchNo, branchAddress, branchPhone) Owner (ownerNo, firstName, lastName, address, telNo) PropertyForRent (propertyNo, street, city,state, zipcode, type, rooms, rent, ownerNo, ownerAddress, ownerName, ownerPhone, staffNo) Client (clientNo, firstName, lastName, telNo, prefType, maxRent, staffNo, dateJoined, branchInfo) Viewing (clientNo, propertyNo, viewDate, comment) Lease (leaseNo, clientNo, propertyNo, rent, paymentMethod, deposit, duration, startDate, endDate) Newspaper (paperName, address, phone, contact) Common Attributes
3
Relational Algebra Operations
Selection Projection Union Set difference Intersection Cartesian product Inner Join Outer Join (predicate) (R) (Att1, Att3) (R) R S R - S R S R S R S
4
Query Examples Produce a list from Staff, showing only lastName, firstName, staffNo, and salary. Staff (staffNo, firstName, lastName, position,address, DOB, salary, branchNo, branchAddress, branchPhone) lastName, firstName, staffNo, salary (Staff) Order of attributes
5
Query Examples Produce a list of all Staff.
Staff (staffNo, firstName, lastName, position,address, DOB, salary, branchNo, branchAddress, branchPhone) Retrieve all attributes when not specified. * (Staff) lastName, firstName, staffNo, salary, position, address, DOB, branchNo, branchAddress, branchPhone (Staff) Different order of attributes
6
List all staff with a salary greater than $30,000.
Staff (staffNo, firstName, lastName, position,address, DOB, salary, branchNo, branchAddress, branchPhone) (salary > 30000) (Staff) All attributes when not specified (salary > $30000) (Staff) // NO! (salary > 30,000) (Staff)
7
List lastName, firstName, staffNo and salary of all staff with a salary greater than $30,000.
lastName, firstName, staffNo, salary ((salary > 30000) (Staff)) (salary > 30000) (lastName, firstName, staffNo, salary (Staff))
8
List the details of all staff members who manage a property in Madison.
Staff (staffNo, firstName, lastName, position, address, DOB, salary, branchNo, branchAddress, branchPhone) PropertyForRent (propertyNo, street, city,state, zipcode, type, rooms, rent, ownerNo, ownerAddress, ownerName, ownerPhone, staffNo) Common attribute? Staff PropertyForRent Staff.* ( city = ‘Madison’(Staff PropertyForRent)) Staff ( staffNo ( city = ‘Madison’ (PropertyForRent)))
9
Staff.* ( city = ‘Madison’(Staff PropertyForRent))
all attributes from both tables Staff.* ( city = Madison(Staff PropertyForRent)) What is Madison? An identifier Staff.* ( city = “Madison” (Staff PropertyForRent)) What is “Madison”? Could be anything but a string
10
List the clientNo, lastName and firstName of all clients who have viewed a property.
Client (clientNo, firstName, lastName, telNo, prefType, maxRent, staffNo, dateJoined, branchInfo) Viewing (clientNo, propertyNo, viewDate, comment) Client.clientNo, lastName, firstName ( Client.clientNo = Viewing.clientNo (Client Viewing)) Client.clientNo, lastName, firstName (Client Viewing)) One client may have reviewed a number of properties, but should be in the result at most once.
11
List the clientNo, lastName and firstName of all clients who have viewed a property.
Also include the properties (propertyNo) they viewed with the date and their comments on the properties Client (clientNo, firstName, lastName, telNo, prefType, maxRent, staffNo, dateJoined, branchInfo) Viewing (clientNo, propertyNo, viewDate, comment) Client.clientNo, lastName, firstName, propertyNo, viewDate, comment (Client Viewing) One client may have reviewed a number of properties, And may be in the result multiple times.
12
List all Properties that have been viewed this year.
Assume there is a function CurrentDate that returns the current date, including year, month, and day. PropertyForRent (propertyNo, street, city,state, zipcode, type, rooms, rent, ownerNo, ownerAddress, ownerName, ownerPhone, staffNo) Viewing (clientNo, propertyNo, viewDate, comment) Common attribute? PropertyForRent.* (viewDate.Year = CurrentDate.Year (PropertyForRent Viewing)) PropertyForRent (join) ( ( propertyNo (viewDate.Year = CurrentDate.Year Viewing))
13
Produce a status report on all properties
Each property Show propertyNo, street, city Also show clientNo, viewDate, and comment from each viewing if the property has been viewed, (Otherwise, use null for the three fields) PropertyForRent (propertyNo, street, city,state, zipcode, type, rooms, rent, ownerNo, ownerAddress, ownerName, ownerPhone, staffNo) Viewing (clientNo, propertyNo, viewDate, comment) PropertyForRent.propertyNo, street, city, clientNo, viewDate, comment (PropertyForRent Viewing)
14
List all pairs of clients (firstName, lastName, telNo) and owners (firstName, lastName, telNo)
if the client has viewed a property owned by the owner. (Use C for Client and O for Owner) Client (clientNo, firstName, lastName, telNo, prefType, maxRent, staffNo, dateJoined, branchInfo) Owner (ownerNo, firstName, lastName, address, telNo, type ) Viewing (clientNo, propertyNo, viewDate, comment) PropertyForRent (propertyNo, street, city,state, zipcode, type, rooms, rent, ownerNo, ownerAddress, ownerName, ownerPhone, staffNo) Client Viewing PropertyForRent Owner C.firstName, C.lastName, C.telNo, O.firstName, O.lastName, O.telNo ( (Client Viewing) (PropertyForRent Owner) ) Common attributes?
15
List all pairs of clients (firstName, lastName, telNo) and owners (firstName, lastName, telNo)
if the client has viewed a property owned by the owner. (Use C for Client and O for Owner) Client (clientNo, firstName, lastName, telNo, prefType, maxRent, staffNo, dateJoined, branchInfo) Owner (ownerNo, firstName, lastName, address, telNo) Viewing (clientNo, propertyNo, viewDate, comment) PropertyForRent (propertyNo, street, city,state, zipcode, type, rooms, rent, ownerNo, ownerAddress, ownerName, ownerPhone, staffNo) Client Viewing PropertyForRent Owner Client (Viewing PropertyForRent ) Owner (Client PropertyForRent ) (Viewing Owner) What’s the common attribute?
16
Assignment 2 Due Wednesday, by noon How to get the symbols?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.