I'm using Mysql 5.7 and I want to use triggers to set up some simple audit trail logging. The table name the entry comes from is relevant so we'd like to capture it. I know I can hard code the name here but I was hoping for something a little more dynamic and portable (copy and paste to another table). Is it possible to get the table name that a given trigger is associated while inside of the trigger?
Here is the guts of my trigger...
BEGIN
SET @table_name = `i_want_the_table_name_for_this_trigger`;
INSERT INTO `test`.`audit_table1` (`serialNumber`, `auditTrailTableName`, `action`, `communicationDate`) VALUES (OLD.id, @table_name, NEW.type, NEW.createdOn);
END
I found this answer for SQL Server... How to get table_name in a trigger - SQL Server
Any help is appreciated.