Advertisement
bebesurf

Question 17 user1

Jun 7th, 2018
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.11 KB | None | 0 0
  1. GRANT SELECT, UPDATE, DELETE, REFERENCES, ALTER ON employe2 TO i1b12b;
  2. GRANT SELECT, UPDATE, DELETE, REFERENCES, ALTER ON service2 TO i1b12b;
  3.  
  4.  
  5. CREATE OR REPLACE TRIGGER sum_duree BEFORE INSERT OR UPDATE OF duree ON i1b12b.copy_travail
  6. DECLARE
  7. rec_employe employe2%ROWTYPE;
  8. BEGIN
  9. SELECT * INTO rec_employe FROM employe2 e
  10. WHERE (SELECT SUM(duree) FROM i1b12b.copy_travail t WHERE e.nuempl=t.nuempl)> e.hebdo;
  11. RAISE_APPLICATION_ERROR (-20004,'Viol de la règle: La somme des durées de
  12. travail dun employé ne peut exceder son temps de travail hebdomadaire');
  13. EXCEPTION
  14. WHEN NO_DATA_FOUND THEN NULL;
  15. WHEN TOO_MANY_ROWS THEN
  16. RAISE_APPLICATION_ERROR (-20005,'Plusieurs erreurs: trop demployés ayant
  17. une durée de travail supérieure à leur temps de travail hebdomadaire');
  18. END;
  19.  
  20.  
  21.  
  22. /*2*/
  23. CREATE OR REPLACE TRIGGER supprimer_employe after DELETE ON i1b12b.copy_travail
  24. BEGIN
  25. DELETE FROM i1b12b.copy_travail t WHERE t.nuempl NOT IN(SELECT nuempl FROM
  26. i1b14b.Employe);
  27. END;
  28.  
  29.  
  30. /*Test trigger*/
  31. INSERT INTO employe2 VALUES(4242, 'Luc', 20, 4, 1500);
  32. INSERT INTO i1b12b.copy_travail VALUES(4242, 103, 10);
  33. DELETE FROM employe2 WHERE NUEMPL=4242;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement