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.

浙公网安备 33010602011771号