Owner: | Production |
Table/View: | Production.WorkOrder |
Creation Date: | 04/26/2006 |
Modification Date: | 04/26/2006 |
Encrypted: | |
Description: | AFTER INSERT trigger that inserts a row in the TransactionHistory table. |
QUOTED_IDENTIFIER: | |
ANSI_NULLS: |
Instead of: | |
Insert: | |
Update: | |
Delete: |
Objects that [Production].[iWorkOrder] depends on
Object Name | Owner | Object Type | Dep Level | |
Flag | dbo | User Defined type | 1 | |
Name | dbo | User Defined type | 1 | |
ErrorLog | dbo | Table | 2 | |
ProductCategory | Production | Table | 2 | |
ProductModel | Production | Table | 2 | |
ScrapReason | Production | Table | 2 | |
UnitMeasure | Production | Table | 2 | |
uspPrintError | dbo | Procedure | 2 | |
ProductSubcategory | Production | Table | 3 | |
uspLogError | dbo | Procedure | 3 | |
Product | Production | Table | 4 | |
TransactionHistory | Production | Table | 5 | |
WorkOrder | Production | Table | 5 |
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [Production].[iWorkOrder] ON [Production].[WorkOrder]
AFTER INSERT AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
INSERT INTO [Production].[TransactionHistory](
[ProductID]
,[ReferenceOrderID]
,[TransactionType]
,[TransactionDate]
,[Quantity]
,[ActualCost])
SELECT
inserted.[ProductID]
,inserted.[WorkOrderID]
,'W'
,GETDATE()
,inserted.[OrderQty]
,0
FROM inserted;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END;
GO
SET QUOTED_IDENTIFIER OFF
GO
GO
SET ANSI_NULLS OFF
GO
See Also
List of table/view triggers