Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. CREATE OR REPLACE TRIGGER jockey_check BEFORE INSERT OR UPDATE ON horse_races
  2. for each row
  3. DECLARE horse_jockey_id number;
  4. first_name_jockey VARCHAR2(100);
  5. first_name_owner VARCHAR2(100);
  6. horse_id number;
  7. owner_id number;
  8. BEGIN
  9. SELECT horse_races.horse_jockey_id INTO horse_jockey_id
  10. FROM horse_races
  11. WHERE
  12. horse_jockey_id = :new.horse_jockey_id;
  13.  
  14. SELECT jockeys.first_name INTO first_name_jockey
  15. FROM jockeys
  16. WHERE
  17. jockeys.id = horse_jockey_id;
  18.  
  19. SELECT horse_jockeys.horse_id INTO horse_id
  20. FROM horse_jockeys
  21. WHERE
  22. horse_jockeys.jockey_id = horse_jockey_id;
  23.  
  24. SELECT horse_owners.owner_id INTO owner_id
  25. FROM horse_owners
  26. WHERE
  27. horse_owners.horse_id = horse_id;
  28.  
  29. SELECT first_name INTO first_name_owner
  30. FROM owners
  31. WHERE
  32. owners.id = owner_id;
  33.  
  34. IF (
  35. first_name_owner = first_name_jockey
  36. )
  37. THEN
  38. raise_application_error(
  39. -20007,
  40. 'The name of jockey cannot be the same as owner.'
  41. );
  42. END IF;
  43. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement