大家好我需要在ORACLE 10g中创建一个触发器,以确保无法输入在birthDate之前的deathDate。我真的很挣钱,请你能提供支持,谢谢亲切的人。
我的计划是:
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*)
谢谢
如果您需要更多信息,请询问
我的关系约束是:
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);
答案 0 :(得分:5)
这种约束应该实现为CHECK
约束
ALTER TABLE actor
ADD CONSTRAINT chk_birth_before_death CHECK( birthDate < deathDate );
如果您确实需要使用触发器强制执行约束(这将更慢并且需要更多工作)
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;