Reputation: 345
Hi guys I need to create a trigger in ORACLE 10g which ensures that a deathDate that is BEFORE the birthDate cannot be entered. I am really struggling on this please can you provide support thank you kind people.
My scheme is:
Actor (actorID, lastName, firstName, middleName, suffix, gender, birthDate, deathDate)
Movie (movieID, title, year, company, totalNoms, awardsWon, DVDPrice, discountPrice)
Quote (quoteID, quote)
Role (roleID ,roleName ,gender ,actorID* ,movieID*)
RoleQuote (roleID*, quoteID*)
Thank you
If there is any more information that you require please ask
My relationship constraint are:
CONSTRAINT_NAME C
------------------------------ -
QUOTE_FK R
ROLE_FK R
MOVIE_ROLE_FK R
ACTOR_ROLE_FK R
ACTORID P
MOVIEID P
QUOTEID P
ROLEID P
ROLEQUOTEID P
Relationships:
ALTER TABLE Role ADD CONSTRAINT ACTOR_ROLE_FK FOREIGN KEY (actorID) REFERENCES Actor (actorID);
ALTER TABLE Role ADD CONSTRAINT MOVIE_ROLE_FK FOREIGN KEY (movieID) REFERENCES Movie (movieID);
ALTER TABLE RoleQuote ADD CONSTRAINT Role_FK FOREIGN KEY (roleID) REFERENCES Role (roleID);
ALTER TABLE RoleQuote ADD CONSTRAINT Quote_FK FOREIGN KEY (quoteID) REFERENCES Quote (quoteID);
Upvotes: 0
Views: 147
Reputation: 231661
That sort of constraint should be implemented as a CHECK
constraint
ALTER TABLE actor
ADD CONSTRAINT chk_birth_before_death CHECK( birthDate < deathDate );
If you really need the constraint to be enforced with a trigger (this will be slower and require more work)
CREATE OR REPLACE TRIGGER check_death_date
AFTER INSERT OR UPDATE ON actor
FOR EACH ROW
BEGIN
IF( :new.birthDate > :new.deathDate )
THEN
RAISE_APPLICATION_ERROR( -20001, 'Birth date cannot be later than death date.' );
END IF;
END;
Upvotes: 5