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)

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: 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. (Please ask for clarifications if you have questions about the relations and/or the semantics of the following queries!).

Express the queries below using Relational Algebra.

1. Find cids and names of courses in which every student majoring in “CDS” enrolled in “Fall2015”.

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

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

4. 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)

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

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

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

Solutions

Expert Solution

RELATIONAL ALGEBRA:

  1. select c.cid, c.cname from Courses c join Students s on c.dept = s.major_dept join Enrollment e on s.sid = e.sid where s.major_dept = 'CDS' and e.sem_year = 'Fall2015';
  2. select s.sid, s.sname from Students s join Courses c on s.major_dept = c.dept join Professors p on c.dept = p.dept where p.pname = 'James';
  3. select p.pid, p.pname from Professors p join Courses c on p.dept = c.dept join Enrollment e on c.cid = e.cid where p.pid NOT IN (select * from Enrollment where sem_year = 'Fall2015');
  4. select c.cid, c.cname from Courses c join Professors p on c.dept = p.dept join Enrollment e on c.cid = e.cid where c.dept = 'CDS' AND p.pid IN (select * from Enrollment where sem_year = 'Fall2015');
  5. select p.pid, p.pname from Professors p join Courses c on p.dept = c.dept where c.dept = 'CDS';
  6. select p.pname, p.pid from Professors p join Courses c on p.dept = c.dept group by p.pname, p.pid having count(*) (select count(*) from Courses c where c.dept = 'CDS'); (or) select p.pname, p.pid from Professors p join Courses c on p.dept = c.dept where c.dept = 'CDS';
  7. select s.sid from Students s join Courses c on s.major_dept = c.dept join Enrollment e on c.cid = e.cid where c.credithours = '3' AND c.dept = 'CDS';

NOTE: column names shouldnot contain '-' so I replaced them with '_'(underscore) like sem-year to sem_year.

I have written relational algebra and also sql statements

The above queries will excute perfectly.

Please give an upvote.

For any queries please do comment I'll update


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), 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...
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...
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.
Consider the following mini-world modeling courses, students, professors, departments, and the like at a single university...
Consider the following mini-world modeling courses, students, professors, departments, and the like at a single university over years. 1. Each department has a unique name. Each department has at most one chairperson who is its head (there are times when a department may not have a chairperson). Each chairperson can be the head of at most one department. 2. Each student has a name, a unique ID, and an address. 3. A professor has a name, a unique ID, and...
INTRO TO DATABASES Consider the boat reservation system: Sailors (sid, sname,rating, age) Boats(bid, bname, color) Reserves...
INTRO TO DATABASES Consider the boat reservation system: Sailors (sid, sname,rating, age) Boats(bid, bname, color) Reserves (sid, bid, day) Formulate the following question in relational algebra using two different sequences of relational operators: A. Find the colors of boats reserved by Lubber. B. Find the sids of sailors older than 20 who have not reserved a red boat.
Consider a university database for the scheduling of classrooms for final exams. This database could be...
Consider a university database for the scheduling of classrooms for final exams. This database could be modeled as the single entity set exam, with attributes course-name, section-number, room-number, and time. Alternatively, one or more additional entity sets could be defined, along with relationship sets to replace some of the attributes of the entity set, as • course with attributes name, department, and c-number • section with attributes s-number and enrollment, and dependent as a weak entity set on course •...
Question (3) Consider the following relations: Student(snum: integer, sname: string, major: string, level: string, age: integer)...
Question (3) Consider the following relations: Student(snum: integer, sname: string, major: string, level: string, age: integer) Class(name: string, meets at: string, room: string, fid: integer) Enrolled(snum: integer, cname: string) Faculty(fid: integer, fname: string, deptid: integer) The meaning of these relations is straightforward; for example, Enrolled has one record per student-class pair such that the student is enrolled in the class. Write the following queries in Oracle SQL. No duplicates should be printed in any of the answers. i) (2 points)...
Consider the following set of requirements for a UNIVERSITY database that is used to keep track...
Consider the following set of requirements for a UNIVERSITY database that is used to keep track of students' transcripts. (a) The university keeps track of each student's name, student number, social security number, current address and phone, permanent address and phone, birthdate, sex, class (freshman, sophomore, ..., graduate), major department, minor department (if any), and degree program (B.A., B.S., ..., Ph.D.). Some user applications need to refer to the city, state, and zip of the student's permanent address, and to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT