Skip to content

Instantly share code, notes, and snippets.

@ObKo
Created May 29, 2012 10:09
Show Gist options
  • Save ObKo/2823857 to your computer and use it in GitHub Desktop.
Save ObKo/2823857 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE TRIGGER check_artist
BEFORE INSERT ON genre_artist
FOR EACH ROW
DECLARE
artist_id INTEGER;
new_id INTEGER;
BEGIN
SELECT id INTO artist_id FROM jobs WHERE name = 'Artist';
SELECT job INTO new_id FROM persons WHERE id = :new.artist;
IF (artist_id != new_id) THEN
RAISE_APPLICATION_ERROR(-20773, 'Not an artist!');
END IF;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment