Midterm Test Even
Midterm Test Even
For each question, copy both SQL code and capture query output in images and paste image
after each question here
Note the primary key and foreign key constraint in your SQL Code
CREATE TABLE departments(
departmentID INT PRIMARY KEY,
departmentName VARCHAR(50) NOT NULL);
Professors Table:
ProfessorID FirstNam LastName DepartmentID
e
1 Alice Johnson 1
2 Bob Smith 2
3 Charlie Brown 3
Courses Table
CourseID CourseName ProfessorID
1 Algorithms 1
2 Calculus 2
3 Quantum 3
Physics
Write an SQL query to get the list of all courses and the professors teaching them. Include a
condition to only retrieve courses in the 'Computer Science' department. Return columns
CourseID, CourseName, ProfessorFirstName, ProfessorLastName. (Total 1 record)
Create a new table called CourseEnrollments which has the following attributes. EnrollmentID is
primary key and automatically increased.
Insert dummy data of records of your choice into newly-created table, at least 4 records. You
can do this via user interface.
Write stored procedure to query which professor taught which course. Return table contains
Professor first name, Professor last name and CourseName. The ProfessorId will be input by
user as input parameter.
Create table EnrollmentLogs which has the following attributes. LogID is primary key and
automatically increased
Create a trigger that logs the changes to EnrollmentLogs to log actions related to
CourseEnrollments. Whenever a new course enrolment record is created, another record is
inserted to EnrollmentLogs. The Action of EnrollmentLogs will accept “INSERT” only since we
need to care Insert action on CourseEnrollments.