開始事物: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
http://wenku.baidu.com/link?url=sOj3AnJPBbeWg6gu2NYcMSfTK4gj8BobB-URG2rCiH8_2lO8gg50qfa8BFuHcOsDHDHK2azmHFOjy9i6AlGBtxtL1xE16Iq9AdUqsXk_rLm