-1

I keep having error messages and i'm not sure what i'm doing wrong. This is the class restaurant:

Restaurant (IdRestaurant, NameRest, Telephone, Address, Forks, NameCity, TypeCooking)

The objective is not allow restaurants with Forks that are not in the interval [1,5]

CREATE TRIGGER CorrecF
BEFORE INSERT ON Restaurant
FOR EACH ROW
BEGIN
    IF (5 < new.Forks AND new.Forks < 1) THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Forks have to be between 1-5';
    END IF;
END;

Another one will be not allowing inserts of Offers that have a date less than 2 weeks from NOW().

Offer (IdOffer, Coffee, Drink, Date, Price, IdRest, Time_Zone)

CREATE TRIGGER CorrectDate BEFORE INSERT ON Offer
 FOR EACH ROW IF (DATE_ADD(NOW(), INTERVAL 2 WEEK) > new.Date) THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Date have to be minimum 2 weeks from now';
    END IF;
END;

1 Answers1

0

You don't appear to be setting delimiters see Delimiters in MySQL and your second trigger (like the first) has compound statements see https://dev.mysql.com/doc/refman/8.0/en/begin-end.html so begin..end is required

P.Salmon
  • 17,104
  • 2
  • 12
  • 19
  • I did as you said, but returns me the following error ''ERROR 1419 (HY000) at line 88: You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)" I tried in phpmyadmin but as the post of delimiters say, it can't be introduced as usual – Mateo Javier Ramón Román Jun 21 '22 at 21:31
  • Search for the error message and phpmyadmin set delimiters – P.Salmon Jun 22 '22 at 05:59