BEGIN TRANSACTION
DECLARE @errorSum int
DECLARE @RID varchar(50)
DECLARE @BID varchar(50)
SELECT @RID=RID FROM Reader WHERE RName='张无忌'
SELECT @BID=BID FROM Book WHERE BName='深入。Net平台和c#编程'
SET @errorSum=0
INSERT INTO Borrow(RID,BID)VALUES (@RID,@BID)
SET @errorSum=@errorSum+@@error
UPDATE Book SET BCount=BCount-1 WHERE BName=' 深入。Net平台和c#编程'
SET @errorSum=@errorSum+@@error
UPDATE Reader SET LendNum=LendNum+1 WHERE RName='张无忌'
SET @errorSum=@errorSum+@@error
IF @errorSum<>0
ROLLBACK TRANSACTION
ELSE
COMMIT TRANSACTION
GO