0
I’m trying to create a trigger
which rotates the control OPTIMIZE mysql.
In short, I have an A table and created a B table that will save a datetime
where this value will be updated every time the table A receives the OPTIMIZE command.
Trigger would
I tried the following code, but Mysql error and I can’t find the solution.
DELIMITER $$
CREATE TRIGGER optimizechattable AFTER UPDATE ON lz_chat_archive FOR EACH ROW
BEGIN
DECLARE @qtd int = 0;
DECLARE @MAXDATE DATE;
DECLARE @DATAATUAL DATE;
SET @qtd = ( SELECT count(c.time) as qtd FROM lz_chats_table_optimize as c );
SET @MAXDATE = ( SELECT MAX(c.time) FROM lz_chats_table_optimize as c );
SET @DATAATUAL = (SELECT GETDATE());
IF(@quantidade <= 0)
optimize table lz_chat_archive;
/* break execution */
END IF;
/* adaptar para , se diferença for maior que x horas, executar if*/
IF (@MAXDATE > @DATAATUAL)
UPDATE lz_chats_table_optimize as c SET c.time = @DATAATUAL where id = 1
optimize table lz_chat_archive;
END IF;
END $$
DELIMITER;
Which error Mysql accuses?
– Aprendiz
Good afternoon , Mysql returns this error: #1064 - 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 'Qtd int = 0; DECLARE MAXDATE DATE; DECLARE CURRENT DATE; ' at line 3
– Henrique Felix