事务:
保障流程的完整执行
保证程序某些程序在运行时同时成功同时失败,保证程序的安全性

begin tran --在流程开始的位置加


--此处写SQL语句

if @@error>0 --ERRORSQL自带的错误提示
begin
rollback tran --回滚事务,到begin tran 的位置,就当没发生过
end

else 
begin

commit tran --提交事务,都没问题,一并提交
end

posted on 2016-08-08 16:32  Lovetolaugh  阅读(114)  评论(0编辑  收藏  举报