I am trying to create a trigger to copy an entire row to an audit table on any UPDATE.
I have 2 tables
Frequencies
and Frequencies_Audit
This is my trigger.
create trigger auditlog
before update on frequencies
for each row insert into
frequencies_audit select frequencies.*;
When I update the record I get Unknown Table frequencies
.
I don't want to have to enter each field name separately if possible since we are constantly adding columns in the database.
Rather than BEFORE UPDATE
, you can write AFTER UPDATE
trigger as follow ::
DELIMITER //
CREATE TRIGGER auditlog AFTER UPDATE ON frequencies
FOR EACH ROW BEGIN
INSERT INTO frequencies_audit select * from frequencies where freqId = NEW.freqId;
END;//
DELIMITER ;
freqId is just a name of Id column. Replace it with the name of Id column in your frequencies table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With