I am going to implement transactions for the many insert statements I have that initialize the database. I understand that a transaction will allow us to either commit the changes to the database, thus saving it. Or if one of the inserts fails, we can roll back all of the inserts that potentially did succeed. My question is, how do I detect if an insert statement has failed?
start transaction;
insert into ..
insert into ..
insert into ..
if (failure) roll back
else commit.
Further explanation,
I have a sql script file that I run to insert a bunch of data into my database. I want to wrap a transaction around these inserts so that when run, if one of them fails then we roll back to the initial state before any inserts executed.