msdn 把这transaction 和错误处理讲得很不错。

有什么不清楚可以看看那个。

这里摘抄重要的几句话。

"
If an error prevents the successful completion of a transaction, SQL Server automatically rolls back the transaction and frees all resources held by the transaction.

 

If a run-time statement error (such as a constraint violation) occurs in a batch, the default behavior in the Database Engine is to roll back only the statement that generated the error.

 

It is important to keep transactions as short as possible. When a transaction is started, a database management system (DBMS) must hold many resources until the end of the transaction to protect the atomicity, consistency, isolation, and durability (ACID) properties of the transaction.

 

A TRY…CATCH construct catches all execution errors that have a severity higher than 10 that do not close the database connection.

 

Errors trapped by a CATCH block are not returned to the calling application."

(如果想返回错误给程序或者客户端,使用RAISERROR)

 

 

相关文章:

  • 2021-06-15
  • 2022-12-23
  • 2022-02-03
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2021-10-14
  • 2022-12-23
  • 2022-02-19
  • 2021-09-19
  • 2022-02-23
  • 2022-12-23
相关资源
相似解决方案