MYSQL Trigger Update Copy entire row

I am trying to create a trigger to copy an entire row to the audit table of 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 a record, I get an Unknown Frequencies table.

I do not want to enter each field name separately if possible, since we are constantly adding columns to the database.

+4
source share
2 answers

Instead of BEFORE UPDATE you can write an AFTER UPDATE trigger as follows:

 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 an id column name. Replace it with the name of the Id column in the frequency table.

+14
source

You can try this

 create trigger auditlog AFTER UPDATE on frequencies for each row insert into frequencies_audit select * from frequencies; 

Because in MYSQL, if you wrote select TableName.* , Then it always returns an Unknown table TableName error.

Maybe this will help you.

0
source

All Articles