Advertisement
Maks140888

Untitled

Jun 6th, 2022
1,170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. create table track_sal_emp (
  2.     id_emp numeric not null,
  3.     dif_sal numeric
  4. );
  5.  
  6. create or replace function process_dif_sal() RETURNS TRIGGER AS $new_Emp$
  7.     BEGIN
  8.         if(TG_OP = 'UPDATE') THEN
  9.             insert into track_sal_emp (id_emp, dif_sal)  VALUES(OLD.empno, NEW.sal - OLD.sal);
  10.         END if;
  11.         return null;
  12.     end;
  13. $new_Emp$ LANGUAGE plpgsql;
  14.  
  15. CREATE TRIGGER chek_dif_sal
  16. AFTER INSERT OR UPDATE OR DELETE ON new_emp
  17.     FOR EACH ROW EXECUTE FUNCTION process_dif_sal();
  18.  
  19. UPDATE new_Emp
  20.     SET sal = 5000
  21.     where sal between 4000 and 4500;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement