DECLARE @PID int 
begin tran 
INSERT INTO LTCY_QualityFeedBack
                           (operatorID, Content, OrderID, title, Operatordate)
                     VALUES (105, '', 1777, '', '2008-7-16 15:02:45')
SET @PID = @@identity
          INSERT 
        INTO LTCY_QualityFeedBackDetail(PID, QualityQuestionID, ClothesID, amount, 
              memo)
VALUES (@PID, 5, 648, 1, '2')
          INSERT 
        INTO LTCY_QualityFeedBackDetail(PID, QualityQuestionID, ClothesID, amount, 
              memo)
VALUES (@PID, 7, 6528888888888888888, 3, '4')
rollback tran 
commit tran 
select @@error+100
  if @@error<>0         rollback tran Tran1
最后一条记录没被插入,前二条被插入了,应当要回滚才对也就是都不要插入呀

解决方案 »

  1.   

    rollback tran
    commit tran 
    这两个是不能放在一起的吧!
      

  2.   

    rollback tran 这个是没有放上去的
      

  3.   

    DECLARE @PID int 
    begin tran 
    INSERT INTO LTCY_QualityFeedBack 
                              (operatorID, Content, OrderID, title, Operatordate) 
                        VALUES (105, '', 1777, '', '2008-7-16 15:02:45') 
    SET @PID = @@identity 
              INSERT 
            INTO LTCY_QualityFeedBackDetail(PID, QualityQuestionID, ClothesID, amount, 
                  memo) 
    VALUES (@PID, 5, 648, 1, '2') 
              INSERT 
            INTO LTCY_QualityFeedBackDetail(PID, QualityQuestionID, ClothesID, amount, 
                  memo) 
    VALUES (@PID, 7, 6528888888888888888, 3, '4') 
    commit tran 
    select @@error+100 
      if @@error <>0         rollback tran Tran1 
      

  4.   

    在每条语句后判断@ERROR,然后如果<>0使用goto语句到rollback tran,在最后的插入语句判断@error,如果=0 goto到commit tran
      

  5.   

    DECLARE @PID int 
    begin tran 
    INSERT INTO LTCY_QualityFeedBack 
                              (operatorID, Content, OrderID, title, Operatordate) 
                        VALUES (105, '', 1777, '', '2008-7-16 15:02:45') 
    SET @PID = @@identity 
              INSERT 
            INTO LTCY_QualityFeedBackDetail(PID, QualityQuestionID, ClothesID, amount, 
                  memo) 
    VALUES (@PID, 5, 648, 1, '2') 
              INSERT 
            INTO LTCY_QualityFeedBackDetail(PID, QualityQuestionID, ClothesID, amount, 
                  memo) 
    VALUES (@PID, 7, 6528888888888888888, 3, '4') 
    rollback tran 
    commit tran 
    select @@error+100 
      if @@error <>0 
         rollback tran Tran1 
    else
       commit ....
      

  6.   


    BEGIN Tran
      OTHER SQL
    IF  @@error<>0   
    BEGIN   
        ROLLBACK   TRAN   
    RETURN   
    END
    Commit Tran

    缺少了判断报错才回滚的机制
      

  7.   

    用事务,必然会加上try catch,否则你怎么知道什么时候commit什么时候rollback?
    rollback tran 
    commit tran 
    放在一起,很无语啊
      

  8.   

    BEGIN Tran 
      执行一条SQL语句 
      IF @@error <>0  
      BEGIN  
        ROLLBACK  TRAN  
        RETURN  
      END 
      执行一条SQL语句
      IF @@error <>0  
      BEGIN  
        ROLLBACK  TRAN  
        RETURN  
      END 
      .....  
    Commit Tran 
      

  9.   

    rollback tran;
    return;不知道这样行不。