MySQL Forums
Forum List  »  Newbie

Re: Inserting data to two tables
Posted by: Peter Brawley
Date: December 13, 2017 12:47PM

> Can I add to the SQL statement a condition that if one of the above "insert" fails to call Rollback?

As Phillip says, in its simplest form Rollback is all-or-none, but if you declare a SAVEPOINT, you can rollback to that defined line, see https://dev.mysql.com/doc/refman/5.7/en/savepoint.html.

You may also need to code actions on specific errors, see Declare Handler and Get Diagnostics in the manual.

If the first insert succeeds, a second insert can apply last_insert_id() to the foreign key column of the child table.



Edited 1 time(s). Last edit at 12/13/2017 12:52PM by Peter Brawley.

Options: ReplyQuote


Subject
Written By
Posted
December 08, 2017 10:18AM
Re: Inserting data to two tables
December 13, 2017 12:47PM
December 13, 2017 01:05PM
December 09, 2017 02:36PM
December 11, 2017 01:15AM
December 13, 2017 12:31AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.