@ammoQ said:Using max(id)+1 is not a good idea - you ask for race conditions that way.  IMO, the easiest way to solve your problem is to create the galery record, including some creation timestamp and a status field that says "temporary". (No need for another database, except maybe for performance reasons...) Once the users adds images, the status goes to "permanent". Then use a "cleanup" job that deletes galery records that are older than e.g. 24 hours and still have a the status "temporary".  I like ammoQ's solution better than mine, especially for the first implementation.  Make sure to use stored procedures or some other abstraction layer so you can distinguish between temporary and permanent types of records.  That way you can (in theory) break them apart later if the spirit moves you.