Trigger creates duplicate records

Asked

Viewed 120 times

0

Mysql "update" Trigger creates 8 records each update. The first record is the old one, the next seven are copies of the change. As I leave only the old and the edited?

I tried to put UNIQUE key on datetime from the "historical" table, but it generates an error. But neither is this solution what I need. I cannot name a Unique key because the same record can be changed several times.

Code entered in Phpmyadmin:

DROP TRIGGER IF EXISTS `placasptc`.`update_bds`//
CREATE TRIGGER `placasptc`.`update_bds` BEFORE UPDATE ON `placasptc`.`bds`
 FOR EACH ROW begin
insert into historico
set hist_action ='update',
bkp_ID = old.ID,
bkp_empresa = old.empresa,
bkp_prefixo = old.prefixo,
bkp_placa = old.placa,
hist_modificado = now(),
hist_usuario = Current_user();
end
  • 1

    certain that the error is not of Rigger, but rather of where you perform the command

  • This update is probably running more than once. Check the locations you run it, and note to see if at any time this UPDATE is not called to another field other than the primary key, if you have the probability of updating multiple records

  • I found. I was doing it for Dreamweaver, and every time I created a communication with the database, I created a new operation, only when I deleted it, the operation continued in the source code. I removed everything and it worked. Thanks for your attention and help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.