This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-15. For the latest, interactive version please visit https://mariadb.com/kb/.

Trigger error

Hello, i'm trying to create check trigger between two columns. But get query error. Structure of columns is: `start_t` (time) , `end_t` (time) The goal is hours in `end_t` don't be same with `start_t` (e.g. 11:00 > 11:00)

Here is query code:

CREATE TRIGGER `check_times` BEFORE INSERT ON `schedule` FOR EACH ROW
BEGIN
DECLARE v_end_time time;
SELECT end_t INTO v_end_time FROM `schedule` WHERE fn_stud = NEW.fn_stud;
IF NEW.start_t > v_end_time THEN SET NEW.fn_stud = NULL;
END IF;
END; 

MySQL says: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

Don't understand what is wrong. Can anyone explain? Thanks.

Answer Answered by Elena Stepanova in this comment.

Did you change the delimiter before executing the SQL above? Since your trigger consists of multiple statements and includes semicolon, you need to do it. See documentation for more detail.

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.