一個SQL Server數(shù)據(jù)庫事務(wù)的使用示例
作者:張超的博客 
  本文主要介紹了SQL Server數(shù)據(jù)庫處理事務(wù)的一個示例,其中涵蓋了開始事務(wù)、提交事務(wù)和回滾事務(wù)等,希望能夠?qū)δ兴鶐椭?/div>  
 
                       
  SQL Server數(shù)據(jù)庫事務(wù)的知識是本文要介紹的內(nèi)容,本文通過一個例子來介紹了SQL Server數(shù)據(jù)庫事務(wù)的使用方法,接下來我們就一起來了解下這部分內(nèi)容。
開始事物:begin transaction
提交事物:commit transaction
回滾事物:rollback transaction
例子:
- begin transaction
 - declare @errorSum int --定義局部變量
 - set @errorSum=0 --初始化臨時變量
 - update bank set currentMoneycurrentMoney= currentMoney-1000 where customerName='張三'
 - set @errorSum=@errorSum+@@error --累計是否有錯誤
 - update bank set currentMoneycurrentMoney= currentMoney+1000 where customerName='李四'
 - set @errorSum=@errorSum+@@error --累計是否有錯誤
 - if @errorSum<>0 --如果有錯誤
 - begin
 - rollback transaction
 - end
 - else
 - begin
 - commit transaction
 - end
 - go
 
關(guān)于SQL Server數(shù)據(jù)庫事務(wù)的使用示例就介紹到這里了,希望本次的介紹能夠?qū)δ兴斋@!
【編輯推薦】
責(zé)任編輯:趙鵬 
                    來源:
                    博客園
  
 
相關(guān)推薦
 
 
 
 














 
 
 