hey, I'm studying for an exam and I'm not too sure if the assertion
i've written is valid, could someone please let me know if this is correct.

Question:

STAFF(Name, Dname, Salary);
DEPT(Name, Budget);

The primary kyes are underlined. The foreign key is
STAFF.Dname -> DEPT.Name. Use SQL to enforce the constraint that the sum of salaries in any department cannot exceed the budget of the department.


My Answer:

CREATE ASSERTION salCheck
CHECK (NOT EXISTS (
SELECT Dname
FROM STAFF s, DEPT d
GROUP BY Dname
HAVING d.Name = s.Dname
AND sum(s.salaray) > d.Budget));

Thanx