存储过程事物

 create  proc sp_submit_topic
 2 
 3 @topicId int,
 4 @content varchar(1000),
 5 @uid varchar(20),
 6 @datetime datetime
 7 
 8 as
 9 
10 begin tran --开发事物
11 
12 insert into tb_re_topic
13 values
14 (
15   @topicId,@uid,@content,@datetime
16 )
17 
18 if @@error<>0 --表示出现了错误
19 begin
20   rollback tran  --回滚 
21 end
22 
23 --没有出现错误,继续向下执行
24 
25 declare @value int
26 
27 select @value=to_num from tb_topic where _id=@topicId
28 
29 update tb_topic set to_num=@value+1 where _id=@topicId
30 
31 if @@error<>0  --再次判断是否出现了错误
32 begin
33   rollback tran
34 end
35 
36 commit tran--  提交事物
posted @ 2009-08-19 10:46  水木  阅读(347)  评论(0编辑  收藏  举报