Hands-on task
SQLite: transfer money in a transaction
The database /root/bank.db has a table accounts(name TEXT, balance INTEGER) with these accounts: Anna has a balance of 100, Boris has 30. Transfer 50 from Anna's account to Boris's. Do it the way it's done with money: both UPDATEs in one transaction (BEGIN ... COMMIT), so they apply together or not at all. In the end Anna should have 50, Boris 80, and the total balance must stay unchanged.
Write the transaction as the script /root/transfer.sql (type it in the Editor tab) and run it in sqlite3.
- transactions
- begin commit
- atomicity
- update
- sqlite3