create proc mypro --创建存储过程
as --必须要写
begin --开启存储过程
begin try --开启异常捕获
begin tran
--select * from [user]
insert into [user] values (343,'李斯','男','吴县')
print 1/0 --制造一个错误
print @@trancount
commit tran --提交事务
end try
begin catch --捕获到错误时
if @@TRANCOUNT > 0
begin
rollback tran
print 'there is a error'
end
print @@trancount
end catch
end
drop proc mypro --删除
exec mypro --执行