AFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the PurchaseOrderHeader table.
Properties
Creation Date
27/10/2017 14:33
Encrypted
Ansi Nulls
Trigger Type
Insert
Delete
Update
After
Instead Of
Trigger Definition
CREATETRIGGER[Purchasing].[uPurchaseOrderHeader]ON[Purchasing].[PurchaseOrderHeader]
AFTER UPDATEASBEGINDECLARE@Countint;
SET@Count=@@ROWCOUNT;
IF@Count=0RETURN;
SET NOCOUNT ON;
BEGIN TRY
-- Update RevisionNumber for modification of any field EXCEPT the Status.
IFNOTUPDATE([Status])
BEGINUPDATE[Purchasing].[PurchaseOrderHeader]SET[Purchasing].[PurchaseOrderHeader].[RevisionNumber]=[Purchasing].[PurchaseOrderHeader].[RevisionNumber]+1WHERE[Purchasing].[PurchaseOrderHeader].[PurchaseOrderID]IN
(SELECT inserted.[PurchaseOrderID]FROM inserted);
END;
END TRY
BEGIN CATCH
EXECUTE[dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF@@TRANCOUNT>0BEGINROLLBACKTRANSACTION;
ENDEXECUTE[dbo].[uspLogError];
END CATCH;
END;