Search code examples
mysqlcascading-deletes

Get the table/primary-key of "cascade-deleted" rows


When I delete an item which triggers some foreign key cascade-deletes, is there a way to get back the table and primary key of the cascade-deleted rows in MySQL?

If there's no built in way to do this, should I just write a stored procedure to manually handle the cascades and then relay what it deleted?


Solution

  • The only way you can do this is by putting a trigger on the table you're cascading to and having it log what deletes were made. MySQL won't nicely push out which deletes happened to you. So you'll either have to select them first, or log them and select them later.