MySQL I : Transactions

1. Login to the MySQL Monitor client.
2. Use the new “movies_db” InnoDB database:
USE movies_db;
3. Start a transaction:
BEGIN;
INSERT INTO directors (first_name, last_name) VALUES (‘Martin’, ‘Scorsese’);
INSERT INTO movies (title, director_id) VALUES (‘The Age of Innocence’, LAST_INSERT_ID());
4. Assuming you typed these correctly you should get no errors. If you get an error, fix and re-enter. To check the relate, type:
SELECT * FROM movies, directors
WHERE movies.director_id=directors.director_id;
5. If acceptable, commit these changes. Type:
COMMIT;

If not acceptable, you would type: ROLLBACK; and begin the transaction again.
6. Check that your changes are commited:
SELECT * FROM movies, directors
WHERE movies.director_id=directors.director_id;