2014-05-01 105 views
1
CREATE TABLE reservation(
    reserv_id int, 
    reserv_date numeric(8,0), 
    start_date numeric(8,0) NOT NULL, 
    end_date numeric(8,0) NOT NULL, 
    payment ENUM('Cash','Credit Card','Check'), 
    PRIMARY KEY(reserv_id), 
    CHECK (reserv_date<start_date), 
    CHECK (start_date<end_date) 
)ENGINE=InnoDB; 


delimiter // 
create trigger date_check 
before insert on reservation 
for each row 
begin 
    IF ((new.reserv_date > new.start_date) or (new.start_date > new.end_date)) THEN SIGNAL 'error message'; 
    END IF; 
end;// 
delimiter ; 

我試圖創建這個觸發器在MySQL,但它不斷拋出我下面的錯誤:MySQL的觸發語法

ERROR 1064(42000):你在你的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以找到在''錯誤信息'附近使用的正確語法; END IF; end'at line 5

我的錯誤是什麼?

回答

1
IF ((new.reserv_date > new.start_date) or (new.start_date > new.end_date)) THEN 
    SIGNAL SQLSTATE '45000' 
    SET MESSAGE_TEXT = 'error message'; 

閱讀documentation瞭解更多詳情。