Rollback and Commit statements when autocommit = 0 or 1
Can I only use the rollback statement if I already used the commit statement in my transaction?
Can I only use the rollback statement when the autocommit parameter is set to 0? If so, how many times can the rollback statement do roll back in this case? Is it still just once?
If autocommit is set to 0, does this mean that none of my transactions are saved until I use the commit statement? By the way, what does being saved entail in this context? Does this suggest that the changes I'm making to the table are being implemented currently, but the database isn't being altered permanently?
Is it true that the commit and rollback statements only operate when autocommit is set to 0? How do their actions alter when autocommit is set to 1?
Thanks for reaching out.
The ROLLBACK command can only be executed if the user has not performed the COMMIT command on the current transaction or statement. COMMIT is the SQL command that is used for storing changes performed by a transaction. When a COMMIT command is issued it saves all the changes since last COMMIT or ROLLBACK. The COMMIT command is used to permanently save the changes done in the transaction in tables/databases. The database cannot regain its previous state. If autocommit=0 then you can use the COMMIT and ROLLBACK commands, otherwise each statement will be committed immediately.
Hope this helps.
So, are you saying the ROLLBACK command will work only when the COMMIT command was NOT performed already and the autocommit = 0, and when it does work it will roll only ONE step back?
By the way, it was me, Ramsey, who asked the question here. :)