SQLite Transaction – Examples
We have employees table with employee id, employee name and employee city name.
We have a employees table and we want to begin transaction as remove those employee whose city is Meerut. Then we ROLLBACK.
BEGIN TRANSACTION
DELETE FROM Employees WHERE CITY='Meerut'
ROLLBACK
Explanation:
In this query we firstly remove those employee who are belong to Meerut then we do ROLLBACK. Since We have not commit/save the database or transaction, which means after ROLLBACK it revoke all the changes that we have performed and make database into original manner and change nothing.
After ROLLBACK, as you can clearly saw that their is no change in database because it ROLLBACK or revoke all the changes.
Let’s understand the importance of COMMIT Command
In above example, if we commit the transaction immidiate after the deletion operation. Then we can’t perform the ROLLBACK operation because it reflect all the channges and store permanently in our disk.
BEGIN TRANSACTION
DELETE FROM Employees WHERE CITY='Meerut'
COMMIT
Explanation: By using commit command, all the changes are reflect and permanently stored in our disk. We can not ROLLBACK or revoke changes after Commit Operation.
SQLite Transaction
SQLite is a database engine. It is a software that allows users to interact with relational databases. Basically, it is a serverless database which means it does not require any server to process queries. With the help of SQLite, we can develop embedded software without any configurations. SQLite is preferable for small datasets. SQLite is a portable database resource. We have an extension of SQLite in any language to access that database.