Not the answer you need?
Register and ask your own question!

How to fix this Trigger for a Percona Mysql database?

KenobiShanKenobiShan EntrantCurrent User Role Novice
I have written a TRIGGER with SELECT but I am getting three errors:


1-SELECT IS NOT VALID AT THIS POSITION FOR THIS SERVER VERSION, EXPECTING '(', WITH".
At line 4


2-concat is no valid input...
At line 5

3-END is no valid at this position...




CREATE DEFINER=`root`@`localhost` TRIGGER `user_AFTER_INSERT` AFTER INSERT ON `user`
FOR EACH ROW
BEGIN
SELECT schema INTO @schema FROM Company WHERE Id = NEW.idCompany;
SET @sql = CONCAT('INSERT INTO `', @schema, '`.`Users` (id, username, dateBirth, idCompany) VALUES(?, ?, ?, ?)';
PREPARE stmt FROM @sql;
SET @id = NEW.id;
SET @username = NEW.username;
SET @dateBirth = NEW.dateBirth;
SET @idCompany = NEW.idCompany;
EXECUTE stmt USING @id, @username, @dateBirth, @idCompany;
DEALLOCATE PREPARE stmt;
END


Server version: 5.6.41-84.1 - Percona Server (GPL), Release 84.1, Revision b308619
Sign In or Register to comment.

MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright ©2005 - 2020 Percona LLC. All rights reserved.