5 questions to test your understanding
A bank has a web app, a mobile app, and an internal admin tool — all of which need to transfer funds between accounts. What is the strongest argument for implementing the transfer logic as a stored procedure rather than in each application?
Inside a stored procedure for a fund transfer, after debiting Account A, you set a SAVEPOINT. Then the credit to Account B fails. You execute ROLLBACK TO SAVEPOINT. What is the state of the transaction?
A stored procedure that wraps a fund transfer in BEGIN/COMMIT/ROLLBACK ensures that either both the debit and credit happen or neither happens.
Rolling back a transaction to a SAVEPOINT permanently commits most of the work done before the savepoint.
Why does putting business logic in a stored procedure provide stronger consistency guarantees than putting the same logic in application code, even if both implementations are correct?