Answer the question
In order to leave comments, you need to log in
How to write mysql trigger to database via Flyway?
There is a sql file containing:
DROP TRIGGER IF EXISTS update_run_result_trigger_update_runner_and_user_names;
CREATE TRIGGER update_run_result_trigger_update_runner_and_user_names
BEFORE UPDATE ON `Run_Result`
FOR EACH ROW
BEGIN
IF NEW.user_id != OLD.user_id AND NEW.user_id IS NOT NULL THEN
SELECT first_name, last_name, nickname INTO @first_name, @last_name, @nickname FROM User WHERE id = NEW.user_id;
SET NEW.user_name = RTRIM(LTRIM(CONCAT(IFNULL(@first_name, ''), ' ', IFNULL(@last_name, ''), ' ', IFNULL(@nickname, ''))));
END IF;
IF NEW.runner_id != OLD.runner_id AND NEW.runner_id IS NOT NULL THEN
SELECT first_name, last_name INTO @first_name, @last_name FROM Runner WHERE id = NEW.runner_id;
SET NEW.runner_name = RTRIM(LTRIM(CONCAT(IFNULL(@first_name, ''), ' ', IFNULL(@last_name, ''))));
END IF;
END;
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 '' at line 6
Answer the question
In order to leave comments, you need to log in
I removed all tabs and spaces, in general I wrote it in one line, it worked
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question