IF ((new.reserv_date > new.start_date) or (new.start_date > new.end_date)) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'error message';
Read the documentation for more details.
Domanda
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 ;
I am trying to create this trigger in MySQL but it keeps throwing me the following error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''error message'; END IF; end' at line 5
What is my mistake?
Soluzione
IF ((new.reserv_date > new.start_date) or (new.start_date > new.end_date)) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'error message';
Read the documentation for more details.