Learning the SQL syntax for SQL transactions

There are a few keywords in MySQL to ensure your SQL queries are in a transaction. To start a transaction in MySQL, use the START TRANSACTION or BEGIN keywords. To commit the transaction, you can use the COMMIT keyword. To rollback a transaction, use the ROLLBACK keyword.

To see a transaction in action, you can execute a query that we used earlier on in this chapter, but this time in a transaction:

USE lahmansbaseballdb;START TRANSACTION;UPDATE managerscopy SET lgID = '--'; 

The previous query updates the managerscopy table and sets all the lgID values to '--', but this time, it's within a transaction, which means if you didn't like the results of the update, you can roll it back. If you are ...

Get Learn SQL Database Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.