SQL Server : is there any performance penalty for wrapping a SELECT query in a transaction?

前端 未结 1 1470
清歌不尽
清歌不尽 2020-12-07 04:50

As learning exercise and before trying to use any ORM (like EF) I want to build a personal project using ADO.NET and stored procedures.

Because I don\'t want my code

相关标签:
1条回答
  • 2020-12-07 05:49

    It all depends on the transaction isolation level. Using the default isolation level (ie. read committed) then your SELECT should occur no performance penalty if is wrapped in a transaction. SQL Server internally wraps statements in a transaction anyway if one is not already started, so your code should behave almost identical.

    However, I must ask you why not use the built-in .Net TransactionScope? This way your code will interact much better with other libraries and frameworks, since TransactionScope is universally used. If you do decide to switch to this I must warn you that, by default, TransactionScope uses SERIALIZABLE isolation level and this does result in performance penalties, see using new TransactionScope() Considered Harmful.

    0 讨论(0)
提交回复
热议问题