Create Procedure Testpro
As
/**/ /*------- Transaction start ----------*/
Begin Transaction Tran_test
/**/ /*-------- Save the transaction ----------*/
Save Transaction Tran_test
/**/ /*-------- Data operation ---------*/
Insert [ Table1 ] ( [ Content ] ) Values ( ' 43332 ' )
/**/ /*---------- Submit a transaction ------------*/
Commit Transaction Tran_test
/**/ /*--------- Determine whether an error exists ----------*/
If ( @ Error <> 0 )
Begin
/**/ /*---------- Custom error output ----------*/
Raiserror ( ' Insert data error! ' , 16 , 1 )
/**/ /*-------- Transaction rollback --------*/
Rollback Transaction Tran_test
End
/**/ /*------- Determine whether the number of transactions is greater than 0 -----------*/
If ( @ Trancount > 0 )
Begin
/**/ /*-------- Transaction rollback --------*/
Rollback Transaction Tran_test
End
Go
A simple example of transaction operations.