DavidSzczesniak
2/9/2018 - 11:40 AM

Transactions

Used to carry out a process in complete isolation from other users, making sure all changes in the transaction can be carried out.

\!h Example - add a new artist and album to the database
START TRANSACTION; -- beginning a set of statements in isolation, to be treated as a block or atomic entity

INSERT INTO artist VALUES (8, "The Cure"); -- modify db

INSERT INTO album VALUES (8, 1, "Disintegration"); -- modify db

COMMIT; -- end transaction and make changes to the db

\!h Example 2 - rollback or abort a transaction
START TRANSACTION; -- transaction started

INSERT INTO artist VALUES(9, "The Wh"); -- statement to modify entered, but has a typo

ROLLBACK; -- abort the transaction completely

SELECT * FROM artist; -- to check that the new artist wasn't added

\!h NOTE: all these are separate statements