I'm looking to create a MySQL trigger on a table. Essentially, I'm creating an activity stream and need to log actions by users. When a user makes a comment, I want a database trigger on that table to fire and:
- Grab the ID of the last inserted row (the id of the comment row).
- perform an INSERT into an activities table, using data from the last inserted row.
I'll essentially replicate this trigger for deleting comments.
Questions I had:
- Is LAST_INSERT_ID() the best way to grab the id?
- How do I properly store the data from the last inserted comment row for use in my "INSERT into activities" statement?
- Should I be using a combination of stored procedures as well as the trigger?
- What would the basic structure of the trigger look like?
Thanks! It's been a few years since I've touched anything to do with DB triggers, procedures and functions.