What's the point to enclose select statements in a transaction?

后端 未结 7 2196
渐次进展
渐次进展 2021-01-31 16:16

What\'s the point to enclose select statements in a transaction? I think select statements are just \"GET\" data from the database, they don\'t have chance to rollback something

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 16:52

    Another reason to use transactions with a select:

    It's possible at some point you may want to invoke your select method from other methods that are participating in a transaction and you want the select to participate in the current transaction. If you have a consistent design where all database actions are performed in a transaction then callers of any method know that it will participate in their transaction.

    For a small up front development cost, this could help avoid some fairly large changes later trying to shoehorn transactions in if/when requirements change or new requirements are added.

提交回复
热议问题