---
title: 事务
date: 2024-06-06T23:51:47Z
tags: []
---


```sql
begin transaction
declare @MyError
set @MyError = 0
begin transaction
语句1
set @MyError += @@error
语句2
set @MyError += @@error

if @MyError = 0
begin
    commit transaction
    print N'成功'
end
else
begin
    rollback transaction
    print N'失败'
end
```

‍
