Context:
- I have a multi-step form. When submitted, it calls a sequence of queries that inserts/updates different tables. The queries are dependent with each other (query 1 needs to finish before query 2, and then query 3 runs next, and so on) so it's important that all of them succeed.
- Ideally, if any of the subsequent queries fail, the first queries should have to rollback committed transactions, as the user will have to (possibly) update some fields in the form and resubmit it, causing the sequence of queries to be called again.
- I have a bulk insert query in SQL mode that inserts an array of records to a MSSQL table. Because we are still testing and currently using a dev/test database, there are some test/erroneous data in this db. The query failed because there was one record that was already existing in the db, causing the entire query to fail, and the subsequent queries not getting called anymore.*
Questions:
- do bulk insert queries in GUI mode fail if there is one (or possibly more) set of record that fails to insert? If this is the case, is there a way to skip the failing records, and continue inserting the rest of the records?
- Is there a way to rollback/undo previous successful queries? For example, if Query 1 succeeded, and Query 2 fails, how can I 'cleanly'** undo the records created/updated by Query 1?
Appreciate any suggestions on workarounds!
* I get that this specific scenario is a data integrity issue but I think it would be good to handle this issue for whatever error subsequent queries run into (timeouts, for example.)
** Cleanly as in not having to define a Delete/Update query to manually delete/update the previously inserted/updated row/s.