In any application there are situations where you would have to use transactions. Mostly transactions are used for writes. So you would have situations like modifying multiple data sets and of course all the steps should be in a transaction and follow the ACID characteristics or if you have a high traffic site, you would like to follow the BASE characteristics. Eventually in any case you would be using transactions for writes.
What are the cases where you would have to use transactions for read data. Here are some of the possible situations
- Data made from multiple gets – When the data is made up from multiple gets and each of them are combined together to create a report or do some calculations, you would need a consistent state of the system.
- Defining specific timeout for queries – If you want to set a specific timeout for queries other than the default timeout, or
- Defining specific isolation level – If you want to change the isolation level.
An interesting data point is that irrespective of whether you start a transaction or not, many databases would start a transaction by default for all the queries. The transaction would start at the beginning and end when the query ends.
For most cases you would be better off not defining transactions for read-only data but if you have any of the above situations then it might be required.