保存點提供了一種機制
在不可能發生錯誤的情況下
下面的示例顯示保存點在一個訂購系統中的使用情況
InvCtrl 表有一個 CHECK 約束
SET NOCOUNT OFF
GO
USE pubs
GO
CREATE TABLE InvCtrl
(WhrhousID int
PartNmbr int
QtyInStk int
ReordrPt int
CONSTRAINT InvPK PRIMARY KEY
(WhrhousID
CONSTRAINT QtyStkCheck CHECK (QtyInStk >
GO
CREATE PROCEDURE OrderStock @WhrhousID int
@OrderQty int
AS
BEGIN TRANSACTION StkStock
DECLARE @ErrorVar int
SAVE TRANSACTION StkOrdTrn
UPDATE InvCtrl SET QtyInStk = QtyInStk
WHERE WhrhousID =
AND PartNmbr =
SELECT @ErrorVar = @@error
IF (@ErrorVar =
BEGIN
ROLLBACK TRANSACTION StkOrdTrn
RETURN (SELECT QtyInStk
FROM InvCtrl
WHERE WhrhousID = @WhrhousID
AND PartNmbr = @PartNmbr)
COMMIT TRANSACTION
END
ELSE
COMMIT TRANSACTION
RETURN
GO
insert InvCtrl(WhrhousID
update InvCtrl set QtyInStk=
exec OrderStock
From:http://tw.wingwit.com/Article/program/SQL/201311/16176.html