For this you need to use a trigger. Check to see if the SELECT SUM(pct_time) FROM Works GROUP BY eid values ββthat will exceed 100 after insertion. If so, enter the error.
Do you know triggers? What database system are you using?
EDIT: Check out the documentation for triggers here . Basically what you want is something like this:
CREATE TRIGGER Work_insert_trigger BEFORE INSERT ON Works FOR EACH ROW EXECUTE PROCEDURE check_sum_work();
Then your check_sum_work() routine check_sum_work() check to see if SUM (pct_time)> 100.
Here is the documentation for the trigger procedures, pay attention to the special variable NEW , which allows you to select the element inserted. So you want SELECT SUM(pct_time) FROM Works WHERE eid = NEW.eid and see if this amount exceeds + NEW.pct_time 100.
This may seem rather complicated if you have never seen triggers before, but itβs actually a pretty powerful mechanism that you will learn to appreciate. :)
Here is another example of using PostgeSQL triggers.
Vache source share