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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.