Question

In: Computer Science

Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname,...

Consider the University Database with the following relations:

Professors (pid, pname, dept, ext) Students (sid, sname, major-dept, year)

Courses (cid, cname, dept, credithours)Enrollment (sem-year, sid, cid, grade)

Teaches (pid, cid, sem-year, class-size),

Professors: All professors have professor id (pid), name (pname), department that they work (dept), and a phone number extension for their office (ext). Students: All students have id (sid), name (sname), department for their major (major-dept), and a year (yeari.e, freshman, sophomore, junior, etc). Courses: All courses have a course id (cid), course name (cname), department (dept), and total credit hours(credithours). Enrollment: has a semester year (sem-year), enrolled student id (sid), course id (cid), and grade that student earns (grade). Teaches: has a professor id (pid), course id (cid), semester year (sem-year), and class size (class-size). Attributes “dept” in relations Professors and Courses, and attribute “major-dept” in relation Students have the same domain, and have values like “CDS”, “EE”, “CE”, etc. Attribute “sem-year” has values like “Spring2016”, “Fall2015”, etc. Assume that cids are unique, i.e. if there are multiple sections of a course, each section has a unique cid.

Express the queries below using Relational Algebra.

1.Find sids, names and major-dept of students who enrolled in a course that is taught by professor James. (10 pts)

2.Find pid and names of professors who teach no courses in “Fall2015”. (10 pts)

3.Find cid and cname of courses that are offered by “CDS” department that are taught by professors who are from another department in “Fall2015". (20 pts)

4.Find pid and names of professors who teach only courses offered by “CDS” department. (20 pts)

5.Find pnames and pids of professors who teach every course offered by “CDS” dept. (20 pts)

6.Find sids of students who enroll in “Fall2015” every 3 credit hour course offered by “CDS” department. (20 pts)

7.Find cids and names of courses in which every student majoring in “CDS” enrolled in “Fall2015”. (Bonus question: 10 pts)

Solutions

Expert Solution

Relational Algebra is the formal description of how a relational database operates.It is a procedural query language. The fundamental operations of relational algebra is Select(), Project(), Union(), Set different(-), Cartesian product(X), Rename().

Tables are :

Professors

pid pname dept ext

Students

sid sname major-dept year

Courses

cid cname dept credithours

Enrollment

sem-year sid cid grade

Teaches

pid cid sem-year class-size

Question and Answers

1. Temp(students dept= major-dept professors)

sid, sname,major-dept (pname = "James"(Temp))

2.   pid,pname (cid="NULL" AND sem-year="Fall2015"(professors X Teaches))

3. cid,cname(dept"CDS" AND sem-year="Fall2015")(courses X Teaches)

4. pid,pname(dept="CDS"(professors))

5. pid,pname(dept="CDS"(professors) AND credithours="MAX"(Courses)

6. sid (dept="CDS" AND Credithour="3"(Courses cid=cid Enrollment ) )

7. R(Courses cid= cid Enrollment)

cid,cname (dept= " CDS"ANDsem-year = "Fall2015"(R))


Related Solutions

Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname,...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname, major-dept, year) Courses (cid, cname, dept, credithours) Enrollment (sem-year, sid, cid, grade) Teaches (pid, cid, sem-year, class-size) where, Professors: All professors have professor id (pid), name (pname), department that they work (dept), and a phone number extension for their office (ext). Students: All students have id (sid), name (sname), department for their major (major-dept), and a year (year i.e, freshman, sophomore, junior, etc). Courses:...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname,...
Consider the University Database with the following relations: Professors (pid, pname, dept, ext) Students (sid, sname, major-dept, year) Courses (cid, cname, dept, credithours) Enrollment (sem-year, sid, cid, grade) Teaches (pid, cid, sem-year, class-size) where, Professors: All professors have professor id (pid), name (pname), department that they work (dept), and a phone number extension for their office (ext). Students: All students have id (sid), name (sname), department for their major (major-dept), and a year (year i.e, freshman, sophomore, junior, etc). Courses:...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain text file, write the following queries in SQL: 1.Find the names of all suppliers who supply a green part. 2.Find the names of all suppliers who are from Illinois. 3.Find the names of all suppliers who sell a red part costing less than $100. 4.Find the names and colors of all parts that are green or red. In writing these (basic) queries you may...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain text file, write the following queries in SQL: Find the names of all suppliers who supply a green part. Find the names of all suppliers who are from Illinois. Find the names of all suppliers who sell a red part costing less than $100. Find the names and colors of all parts that are green or red. In writing these queries you may make...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) write the following...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) write the following queries in SQL: * Find the names of all suppliers who supply a green part. *Find the names of all suppliers who are from Illinois. *Find the names of all suppliers who sell a red part costing less than $100. *Find the names and colors of all parts that are green or red. In writing these queries you may make the following assumptions: a....
Consider the following schema: Suppliers (sid, sname, address) Parts (pid, pname, colour) Catalog(sid, pid, cost) The key for Suppliers is sid, for Parts is pid, and for Catalog is sid and pid The Ca...
Consider the following schema: Suppliers (sid, sname, address) Parts (pid, pname, colour) Catalog(sid, pid, cost) The key for Suppliers is sid, for Parts is pid, and for Catalog is sid and pid The Catalog relation associates prices charged for parts by suppliers. Write the following queries using relational algebra. For items (a) through (e), use the "sequences of assignments" form. For items (f) and (g), use the "expression tree" form. List all assumptions. (Some marks will be given for the quality of your answers.) (a) Find...
INRO TO DATABASES Consider the following Schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname:...
INRO TO DATABASES Consider the following Schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) The Catalog relation lists the prices charged for parts by Suppliers. Write the following queries in SQL using join, nested queries and set operators. 1. Find names of suppliers who supply every red or green part. 2. Find the sids of suppliers who supply every red part or supply every green part. 3. Find sids...
Consider the following schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string)...
Consider the following schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) The key fields are underlined, and the domain of each field is listed after the field name. Therefore sid is the key for Suppliers, pid is the key for Parts, and sid and pid together form the key for Catalog. The Catalog relation lists the prices charged for parts by Suppliers. WRITE THE FOLLOWING QUERIES IN RELATIONAL ALGEBRA...
Given a relational database that consists of the following relations: Performer (pid: integer, pname: string, years_of_experience:...
Given a relational database that consists of the following relations: Performer (pid: integer, pname: string, years_of_experience: integer, age: integer) Movie (mname: string, genre: string, minutes: integer, release_year: integer, did: integer) Acted (pid: integer, mname: string) Director (did: integer, dname: string, earnings: real) Do the following using your Azure SQL database: a) Use SQL statements to create the relations. b) Populate the relations using SQL statements with the given data posted on Canvas. c) Implement the SQL queries for the following:...
INTRO TO DATABASE Consider the Sailors-Boats-Reserves database described below. Sailors(sid: integer, sname: string, rating: integer, age:...
INTRO TO DATABASE Consider the Sailors-Boats-Reserves database described below. Sailors(sid: integer, sname: string, rating: integer, age: real) Boats(bid: integer, bname: string, color: string) Reserves(sid: integer, bid: integer, day: date) Write each of the following queries in SQL. 1. Find the names and ages of sailors who have reserved at least two boats. 2. For each boat reserved by at least 2 distinct sailors, find the boat id and the average age of sailors who reserved it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT