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
最后一条记录没被插入,前二条被插入了,应当要回滚才对也就是都不要插入呀
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
最后一条记录没被插入,前二条被插入了,应当要回滚才对也就是都不要插入呀
commit tran
这两个是不能放在一起的吧!
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
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 ....
BEGIN Tran
OTHER SQL
IF @@error<>0
BEGIN
ROLLBACK TRAN
RETURN
END
Commit Tran
缺少了判断报错才回滚的机制
rollback tran
commit tran
放在一起,很无语啊
执行一条SQL语句
IF @@error <>0
BEGIN
ROLLBACK TRAN
RETURN
END
执行一条SQL语句
IF @@error <>0
BEGIN
ROLLBACK TRAN
RETURN
END
.....
Commit Tran
return;不知道这样行不。