C # and SQL Server: any reason to put one INSERT in a transaction?

Using C # and SQL Server, would there be any reason to put one INSERT statement in a transaction?

I am looking at code written by someone else. I cannot understand why a transaction is needed, since there is only one SQL statement.

+4
source share
3 answers

Programmatically, there would be no reason. However, the reason may be in readability; wrapping an arbitrary piece of code in a transaction is a pretty good way to draw the attention of future developers to it - or from something else. It might also just be that the best practice at the time of writing was to wrap any database transactions in a transaction, just like wrapping stuff in try / catch-blocks.

My suggestion: If because of this, the code becomes more understandable and readable, or if all other database calls are in transactions, leave it. Otherwise, delete it.

0
source

It will already be in an implicit transaction . No need to wrap it in another redundant transaction.

+9
source

No reason at all.

+3
source

All Articles