开发者

Sql Server 2005 Transactions For Deployment Scripts

I want to wrap my SQL deployment script in a transaction (containing a bunch of schema changes). I am doing this because if one part of it fails, I want the db to revert to wha开发者_如何学运维t it was before I ran the script.

I have a few simple questions I would like to have resolved prior to pushing these changes:

  1. Is it necessary to explicitly call COMMIT on the transaction at the bottom of the script?
  2. Is it necessary to explicitly check for errors and call ROLLBACK at the bottom, or will simply using a transaction provide this effect?


  1. Yes.

  2. Yes.

You should also investigate SET XACT_ABORT ON. SET XACT_ABORT ON instructs SQL Server to rollback the entire transaction and abort the batch when a run-time error occurs.

This article Error Handling in SQL 2005 and Later is worth reading.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜