Should I be using SQL transactions, while reading records?

后端 未结 7 1683
离开以前
离开以前 2021-01-02 09:14

SQL transactions is used for insert, update, but should it be used for reading records?

7条回答
  •  情深已故
    2021-01-02 09:48

    Transactions are meant to avoid concurrency issues when one logical transaction actually maps to several SQL queries. For example, for a bank account, if you are transferring money from one account to another, you will 1st subtract the amount from account and then add it to other(or vice versa). But, if some error occurs in between your database would be in a invalid state (You may have subtracted the amount from one account but not added it to other). So, if you are reading all your data in one query, you dont need a transaction.

提交回复
热议问题