how do you enforce business rules on a database code example

Example: how do you enforce business rules on a database

create trigger branch_manager_trg 
     before insert or update on branch_manager   
     for each row
declare
    dummy employee.employee_id%type;
begin
    select e.employee_id
    into dummy
    from employee e
    where e.employee_id = :new.manager_id
    and e.branch_id = :new.branch_id
    and e.emp_type = 'MANAGER';
exception
  when no_data_found then
       raise_application_error(-20000, 'Branch manager must be a MANAGER');
end;
/

Tags:

Misc Example