From the course: MySQL Advanced Topics (2019)

What are transactions?

- In database terminology, A transaction is a group of operations that are handled as one unit of work. In practice, this means that you may have many operations and if any of these operations fails, the entire group of operations is treated as failed and the database is restored to its state before the group of operations was begun. For example, imagine a financial application where several tables need to be updated for a given transaction. If any of these operations fails, corresponding data in the other tables would be out of sync and invalid. By combining all of these actions into a single transaction, the state of the database will be automatically rolled back to a valid state if any of the individual operations fails. Transactions are also used to ensure that concurrent operations result in a state as if they were handled separately and sequentially. In other words, if your database is used by many clients at the same time and they're all conducting similar complex operations grouped into transactions those transactions will affect the database as if each transaction were completed separately. Transactions could also improve performance, sometimes radically. For example, if you have a lot of rows to insert into a table, or set of tables, each of these inserts takes time to write to the storage device. When making individual writes, the database system uses resources to ensure that each row has been successfully committed to storage. When you make a group of inserts into your table as a transaction, the database can perform many write operations together significantly reducing the overhead associated with writing to physical media. Generally, transactional database operations can improve reliability and performance for larger or more complex operations.

Contents