What does a transaction around a single statement do?

It does nothing. All individual SQL Statements, (with rare exceptions like Bulk Inserts with No Log, or Truncate Table) are automaticaly “In a Transaction” whether you explicitly say so or not.. (even if they insert, update, or delete millions of rows).

EDIT: based on @Phillip’s comment below… In current versions of SQL Server, Even Bulk Inserts and Truncate Table do write some data to the transaction log, although not as much as other operations do. The critical distinction from a transactional perspective, is that in these other types of operations, the data in your database tables being modified is not in the log in a state that allows it to be rolled back.

All this means is that the changes the statement makes to data in the database are logged to the transaction log so that they can be undone if the operation fails.

The only function that the “Begin Transaction”, “Commit Transaction” and “RollBack Transaction” commands provide is to allow you to put two or more individual SQL statements into the same transaction.

EDIT: (to reinforce marks comment…) YES, this could be attributed to “superstitious” programming, or it could be an indication of a fundamental misunderstanding of the nature of database transactions. A more charitable interpretation is that it is simply the result of an over-application of consistency which is inappropriate and yet another example of Emersons euphemism that:

A foolish consistency is the hobgoblin of little minds,
adored by little statesmen and philosophers and divines

Leave a Comment