One Pager Cheat Sheet
- A SQL transaction is a collection of one or more SQL statements that communicate with a database, typically used for preserving database integrity in cases of concurrent execution of multiple related operations or interactions.
- By guaranteeing atomicity, ensuring consistency, allowing for isolation, and providing durability, SQL Transactionsuphold theACIDproperties.
- Atomicity is a ACID property that ensures that a transaction is either fully committed or not at all, preventing anyinconsistent datafrom being stored in the database.
- The transaction controlcommandsBEGIN TRANSACTION,COMMIT,ROLLBACK,SAVEPOINT,RELEASE SAVEPOINTandSET TRANSACTIONare used to manage, save, reverse and name transactions.
- We will perform two SQL transactionson the table shown to illustrate examples of transactions.
- By running a BEGIN TRANSACTION, entering various SQL statements such as INSERT, UPDATE commands and then COMMIT TRANSACTION, all the changes will be saved to the database and cannot be reverted back.
- All changes during a SQL transaction are undone using the ROLLBACKcommand, so that the resulting table looks exactly the same as before.
- The only way to recover the database to its previous state after a COMMITstatement is executed is by executing aROLLBACKcommand, however this will only reverse actions taken after the last COMMIT or ROLLBACK command.



