0

Is there a way to roll back a transaction later in time? I want to make a function, where the user can upload an excel file and than the data it contains converted into sql inserts inside a transaction. If there is an error, I can roll back the transaction, but I also would like to be able to roll it back when the user wants to. So, basically it is an UNDO LAST SESSION/UPLOAD function to this section.

I am using PHP5.4, Laravel 4.2 and MySQL5.5

szab.kel
  • 2,356
  • 5
  • 40
  • 74

1 Answers1

0

Rollback is a technical term in database operations; it has a precise meaning related to transactions.

What you're proposing to do doesn't sound like a rollback. It sounds like deleting rows--deleting rows at an arbitrary time. (Arbitrary time, because last session could be hours or days or weeks ago, right?)

As long as you know which keys are involved--and that might not be a simple thing to do--you can delete rows by using the keys. And you can do this regardless of the dbms and regardless of the ORM or web framework.

One complication in the general case is that committed rows are visible to other transactions. So other transactions--and other users--might use some of your rows in foreign key references. This will greatly complicate deleting rows.

Mike Sherrill 'Cat Recall'
  • 91,602
  • 17
  • 122
  • 185
  • So, there is no automatic way to do this in MySQL (and I guess, in other DBMS too). I need to save the id-s and manually delete these rows if possible. Hmm. – szab.kel Aug 01 '14 at 13:25