Question: Consider the following SQL schema: create table Courses ( id integer primary key, code text, title text, quota integer check ( quota between 1 and

Consider the following SQL schema:
create table Courses (
id integer primary key,
code text,
title text,
quota integer check (quota between 1 and 9999),
...
);
create table Enrolments (
student integer references Students(id),
course integer references Courses(id),
...
);
Which of the following assertions captures the requirement that the total number of students enrolled in a course cannot be greater than the course quota?
(a)
create assertion check_quota
check (not exists (
select *
from Courses c join Enrolments e on (e.course = c.id)
group by e.student
having count(*)> c.quota
)
);
(b)
create assertion check_quota
check (not exists (
select *
from (select c.id, count(student) as nstu, c.quota
from Courses c join Enrolments e on (e.course = c.id)
group by c.id, c.quota
) as x
where x.nstu > x.quota
)
);
(c)
create assertion check_quota
check (not exists (
select *
from Courses c
where c.quota >=(select count(*) from Enrolments e where e.course = c.id)
)
);
(d)
None of the above is correc

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!