SQL Server数据库事务的知识是本文要介绍的内容,本文通过一个例子来介绍了SQL Server数据库事务的使用方法,接下来我们就一起来了解下这部分内容。
开始事物: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
关于SQL Server数据库事务的使用示例就介绍到这里了,希望本次的介绍能够对您有所收获!