Starting with a MySQL trigger like this:
delimiter #
create trigger comments_after_ins_trig after insert on comments
for each row
begin
insert into comment_types (comment, user_id) values (new.comment, new.user_id);
end#
Let’s say I wanted to split the inserts into different table, for instance if comment contains a vulgar word (LOCATE('sh**', comment) > 0), instead of comment_types I want to insert into a table called vulgar_comments, if the comment contains the words “thanks” or “nice” insert into nice_comments, etc. Basically how do I make the table name to insert into variable for that trigger?
Try this one, I have tested this and this works on my end: