0
I have this table:
create table alecrim(
id_alecrim int not null auto_increment,
sem_epi int not null,
p1 smallint,
p2 smallint,
p3 smallint,
p4 smallint,
p5 smallint,
p6 smallint,
p7 smallint,
p8 smallint,
p9 smallint,
totOvos int,
pend tinyint,
ext tinyint,
ano varchar(4),
primary key(id_alecrim)
) default charset = utf8;
And this Rigger:
CREATE TRIGGER somaOvosIFS BEFORE UPDATE
ON alecrim
FOR EACH ROW
DELIMITER \\
begin
SET NEW.totOvos = NEW.p1 + NEW.p2 + NEW.p3 + NEW.p4 + NEW.p5 + NEW.p6 + NEW.p7 + NEW.p8 + NEW.p9;
IF(old.pend > 0) THEN
NEW.pend = old.pend - 1;
END IF;
END \\
The goal of Trigger is to update the fields in question (until then it works) and if the Pend field is greater than 0 it updates its value with the operation in question.
Someone helps?
Hello Amiraldo. You can accept your own answer to mark that the problem has been solved.
– Anthony Accioly
@Anthonyaccioly So you don’t need to edit the question title?
– Amiraldo Rodrigues Filho
Exactly, there’s no need to change the headline by accepting your own answer (or that of any other member).
– Anthony Accioly