Search code examples
.netdata-accesssqltransaction

When should I use a SQLTransaction


What is the appropriate time to use a SQLTransaction?

I use them for all of my INSERT, UPDATE and DELETE statements.

Is this the correct usage or am I doing a bit of overkill?


Solution

  • Use a transaction when you want a series of statements to be treated atomically - that is either they all succeed and are committed, or they are all rolled back.

    Since simple statements are already atomic you don't need to explicitly create a transaction around each and every individual statement.