天若有情.NET

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

Using SQL Server Transactions

比较好用,贴出来:

Using SQL Server Transactions
In complicated relational database applications there are circumstances where a SQL query must be executed in its entirety or not at all in order to preserve the integrity of the database. SQL Server transactions provide this functionality, as well as error handling.

Transactions are very simple to use. You place the code to execute after a BEGIN TRANSACTION declaration, then when it has completed, check the @@ERROR variable to determine whether to commit or rollback the transaction.

BEGIN TRANSACTION AddClient -- SQL code which must either run as either all or nothing

IF @@ERROR = 0
   COMMIT TRANSACTION AddClient
ELSE
BEGIN
   PRINT @@ERROR
   ROLLBACK TRANSACTION AddClient
END
© Copyright Quantum Software Solutions 2003, All rights reserved.

posted on 2005-01-27 13:04  pathik  阅读(351)  评论(0)    收藏  举报