Not enough to notice.
That is, each TXN will be open for an additional OhNoSecond between the BEGIN TRAN and INSERT. I would be impressed if anyone could measure it.
However, if you made a BEGIN TRAN, then you were prompted to introduce a user, your legs need to be broken ...
Good idea: I do this, so all my notes are 100% written, have the same error handling, can be nested, etc.
Edit: after Remus's answer, I see that I did not refer to the template for my TXN socket: Nested stored procedures containing the TRY CATCH ROLLBACK template? This differs from Remus in that it always rolls back and does not have SAVEPOINT
Edit, quick and dirty test shows that this happens faster than 2/3 of the time with a transaction
SET NOCOUNT ON SET STATISTICS IO OFF DECLARE @date DATETIME2 DECLARE @noTran INT DECLARE @withTran INT SET @noTran = 0 SET @withTran = 0 DECLARE @t TABLE (ColA INT) INSERT @t VALUES (1) DECLARE @count INT, @value INT SET @count = 1 WHILE @count < 100 BEGIN SET @date = GETDATE() UPDATE smalltable SET smalltablename = CASE smalltablename WHEN 'test1' THEN 'test' ELSE 'test2' END WHERE smalltableid = 1 SET @noTran = @noTran + DATEDIFF(MICROSECOND, @date, GETDATE()) SET @date = GETDATE() BEGIN TRAN UPDATE smalltable SET smalltablename = CASE smalltablename WHEN 'test1' THEN 'test' ELSE 'test2' END WHERE smalltableid = 1 COMMIT TRAN SET @withTran = @withTran + DATEDIFF(MICROSECOND, @date, GETDATE()) SET @count = @count + 1 END SELECT @noTran / 1000000. AS Seconds_NoTransaction, @withTran / 1000000. AS Seconds_WithTransaction Seconds_NoTransaction Seconds_WithTransaction 2.63200000 2.70400000 2.16700000 2.12300000
Reversing the update order retains the same behavior.
source share