I want to disable in before insert trigger inserting into table when some condition is true
create or replace trigger CHECK_FOR_MAX_ENTRANTS
before insert on application
declare
entrants_count number;
max_entrants number;
begin
select count(*) into entrants_count from application
where id_speciality = :new.id_speciality;
select max_students_number into max_entrants from speciality s
where s.id_speciality = :new.id_speciality;
IF entrants_count >= max_entrants THEN
**disable this insert**
end;
How can i do this?
Assuming you’re talking about Oracle, then, in place of disable this insert you could:
See: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/errors.htm#sthref2006
EDIT: It’s generally a bad idea to have inserts fail silently (what you’re asking for). You also may run into mutating table errors if you try to delete the record in an after insert trigger.
Instead, just don’t insert the record to begin with.
One way you could probably achieve this is to add something like this to the end of your insert statement:
This should only execute the insert statement when entrants_count < max_entrants (what you want).