When to use Transactions in SQL Server

后端 未结 4 1854
南笙
南笙 2021-01-30 11:11

There are lots and lots of questions on HOW to use Transactions. What I want to know is WHEN? Under what circumstances? What types of queries? Can Try-Catch blo

4条回答
  •  面向向阳花
    2021-01-30 11:48

    You use transactions when the set of database operations you are making needs to be atomic.

    That is - they all need to succeed or fail. Nothing in between.

    Transactions are to be used to ensure that the database is always in a consistent state.

    In general, unless there is a good reason not to use them (long running process for instance), use them. See this blog post for details.


    Try/Catch blocks have nothing to do with transactions - they are used for exception handling. The two concepts are not related and are not replacements for each other.

提交回复
热议问题