For the following problems, consider the following schema of a University database:…
- User
For the following problems, consider the following schema of a University database: Student(sid: integer, name: string, address: string, gpa: real) grade: real) Section(cid: integer, semester: integer, taught_by: integer) Course(cid: integer, title: string, department: string) The relation Enrollment records that a Student sid enrolled in Section (cid, semester) and obtained the given grade. The primary key of a relation consists of all its underlined attributes. There are foreign key constraints between (Enrollment.cid, Enrollment.semester) and (Section.cid, Section.semester), Enrollment.sid and Student.sid, and Section.cid and Course.cid. Problem 1: Relational Algebra (RA) queries (20 marks) Formulate the following queries in RA. a) Find the sid of Students who have been enrolled in all Courses of department “CMPT”. 10 marks b) Find the cid and title of Courses that have had at least two different Sections. 10 marks Problem 2: SQL queries (20 marks) Formulate the following queries in SQL. Use capital letters for SQL keywords. a) Find the name of Students who have been enrolled in all Courses of department “CMPT”. 10 marks b) Find the cid and title of Courses that have had at least two different Sections. 10 marks
- Assistant
Problem 2a: SQL Query
Objective:
Find the names of students who have been enrolled in all courses from the department "CMPT".Approach:
To identify students who are enrolled in every "CMPT" course, we can use theNOT EXISTSclause to ensure there is no "CMPT" course that a student has not enrolled in. This involves:- Selecting all students.
- For each student, checking that there does not exist any "CMPT" course for which the student is not enrolled.
SQL Query:
SELECT S.name FROM Student S WHERE NOT EXISTS ( SELECT C.cid FROM Course C WHERE C.department = 'CMPT' AND NOT EXISTS ( SELECT E.sid FROM Enrollment E WHERE E.sid = S.sid AND E.cid = C.cid ) );