News & UpdatesProgrammingWeb programming Store My Projects

SQL Tutorial – 08 – Transaction

The transaction controls lets you execute a group of update statements as if they were a single operation, so that if one of them fails all of the previous statements will be undone.

Begin Work

The BEGIN WORK statement marks the start of a database transaction. You can then execute any number data manipulation statements (INSERT, UPDATE, and DELETE).

-- Transaction Example
UPDATE mytable SET acc1 = acc1 - 200 WHERE id = 1;


These changes won’t be visible to other users until a COMMIT statement is made, which finalizes the transaction. If you execute a data definition statement (CREATE, ALTER, or DROP) that will also end the transaction, as if there were a COMMIT before the statement.



If either of the data manipulation statements fails the whole transaction will be undone. You can also explicitly undo the transaction with the ROLLBACK statement.

Recommended additional reading:
Sams - Teach Yourself SQL in 10 Minutes