I'm trying to wrap all my transactions that should be all-or-nothing into BEGIN and COMMIT, but I'm not sure how to do this in cases like the following.
I have 3 tables, one for images, one for albums, and one for the relations between them, namely album_images. The way the system works is that a user can create an album and fill it with his images in one operation. The SQL is as follows:
BEGIN;
INSERT INTO albums [...]; -- Create a new album row
SELECT id AS album_id FROM albums WHERE [...]; -- Get that rows ID
-- Now use album_id in the next statement
INSERT INTO album_images (album_id, image_id) [...];
COMMIT;
This is probably a common problem, I'm just not sure what to search for and I can't seem to find a solution in the documentation either.