事务

sql-事务

开始执行事务:begin transaction

提交事务:commit transaction

回滚:rollback transaction

栗子:

begin transaction

DECLARE @tran_error int;
SET @tran_error = 0;

BEGIN TRY 

update student set age=23 where name='小哥哥'

End try

BEGIN CATCH
    SET @tran_error = @tran_error + 1
   END CATCH
IF(@tran_error > 0)
    BEGIN
        rollback transaction
    END
ELSE
    BEGIN
       commit transaction
    END

 

posted @ 2018-05-15 22:48  newRohLzy  阅读(107)  评论(0编辑  收藏  举报