Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE TRIGGER jockey_check BEFORE INSERT OR UPDATE ON horse_races
- for each row
- DECLARE horse_jockey_id number;
- first_name_jockey VARCHAR2(100);
- first_name_owner VARCHAR2(100);
- horse_id number;
- owner_id number;
- BEGIN
- SELECT horse_races.horse_jockey_id INTO horse_jockey_id
- FROM horse_races
- WHERE
- horse_jockey_id = :new.horse_jockey_id;
- SELECT jockeys.first_name INTO first_name_jockey
- FROM jockeys
- WHERE
- jockeys.id = horse_jockey_id;
- SELECT horse_jockeys.horse_id INTO horse_id
- FROM horse_jockeys
- WHERE
- horse_jockeys.jockey_id = horse_jockey_id;
- SELECT horse_owners.owner_id INTO owner_id
- FROM horse_owners
- WHERE
- horse_owners.horse_id = horse_id;
- SELECT first_name INTO first_name_owner
- FROM owners
- WHERE
- owners.id = owner_id;
- IF (
- first_name_owner = first_name_jockey
- )
- THEN
- raise_application_error(
- -20007,
- 'The name of jockey cannot be the same as owner.'
- );
- END IF;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement