第一次写事务语句,求大虾们帮看看,这样写有没有问题?
谢谢
begin transaction t1
update table1 set ...
set @Isok = 1
IF @@ERROR <> 0 
ROLLBACK
Else
COMMIT

解决方案 »

  1.   

    完整点的
    begin transaction t1
        update table1 set ...
        set Isok = 1
        IF @@ERROR <> 0 
            ROLLBACK transaction t1
        Else
            COMMIT transaction t1
      

  2.   


    begin transaction t1
        update table1 set ...
        set @Isok = 1    IF @@ERROR <> 0 
            ROLLBACK transaction t1
        Else
            COMMIT transaction t1
    end  transaction t1
      

  3.   

    谢谢hyde100 兄弟,
    那再虚心请教下,如果在ROLLBACK和COMMIT后面不加transaction t1语句

    不加end  transaction t1语句的话
    如果出意外的话,会酿成什么后果呢?
    谢谢
      

  4.   

    还有,我刚才在mssql2005中把语句
    end  transaction t1
    加上后就提示出错"关键字 'transaction' 附近有语法错误。"
    这是为什么呢?
    求达人指教.
      

  5.   

    将end  transaction t1去掉
      

  6.   

    参考msdn学习
    http://msdn.microsoft.com/zh-cn/vstudio/ms188929.aspx
      

  7.   

    BEGIN TRAN T1
    UPDATE table1 ...
    BEGIN TRAN M2 WITH MARK
    UPDATE table2 ...
    SELECT * from table1
    COMMIT TRAN M2
    UPDATE table3 ...
    COMMIT TRAN T1