LAST_INSERT_ID () in trigger
Hello,
I need to create an audit trigger when every insert I reply that table. It happens that this table has a auto_increment field, in this case how can I do to get the value of the next value of the auto_increment, tried to use the the function N = (select LAST_INSERT_ID ()), adding 1 more, but he always writes one, never key value of the table ..
follows my trigger
DELIMITER //
CREATE TRIGGER diretopg BEFORE INSERT ON direto FOR EACH ROW
BEGIN
DECLARE N int(11);
declare dtagendamento datetime;
set N=(select LAST_INSERT_ID())+1;
if new.agendamento = '0000-00-00 00:00:00' then set dtagendamento = null;
end if;
INSERT INTO diretopg values(
N,
new.remetente ,
new.destinatario,
new.textosms,
new.campanha ,
new.dataenvio ,
dtagendamento,
new.status ,
new.situacao,
new.tipo ,
new.ag ,
new.qnt ,
new.sms ,
new.prioridade,
new.cpf);
END; //
DELIMITER ;