Anda dapat memeriksa batasan ini dalam pemicu setelah memasukkan atau memperbarui pada tabel kutukan.
CREATE or replace TRIGGER check_leader
AFTER INSERT OR UPDATE ON Course
FOR EACH ROW
declare
v_type varchar2(30);
BEGIN
select type into v_type from stuff where :NEW.leader_id = stuff.stuff_id;
if v_type != 'teacher' then
RAISE_APPLICATION_ERROR(-20000, 'course leader must be teacher');
end if;
end;
/
Tetapi Anda memerlukan pemicu lain di tabel staf. Dalam kasus perubahan jenis barang (dari teacher ke cleaner ) Itu harus diperiksa untuk entri di tabel kutukan.
CREATE or replace TRIGGER check_courses
AFTER UPDATE ON STUFF
FOR EACH ROW
declare
v_num number;
BEGIN
if :OLD.type = 'teacher' and :NEW.type != 'teacher' then
select count(*) into v_num from curses where courses.leader_id = :NEW.stuff_id;
if v_num > 0 then
RAISE_APPLICATION_ERROR(-20000, 'there are courses assigned ');
end if;
end if;
end;
/