Trigger:
[AdventureWorks2016CTP3].[Production].[iWorkOrder]
on
Table WorkOrder
Trigger properties
| Name | Value |
| Schema | [Production] |
| Owner | [dbo] |
| Creation date | 16.11.2015 |
| Encrypted | |
| Disabled | |
| ID | 989246579 |
| Implementation type | Transact SQL |
Creation options
| Name | Value |
| QUOTED_IDENTIFIER | ON |
| ANSI_NULLS | ON |
Type
| Instead of | Insert | Update | Delete |
![]() |
Objects that [Production].[iWorkOrder] depends on
| Object name | Object type | Dep level |
| [Production] | Schema | 1 |
| [dbo].[uspLogError] | Procedure | 1 |
| [dbo].[uspPrintError] | Procedure | 1 |
| [Production].[TransactionHistory] | Table | 1 |
| [Production].[WorkOrder] | Table | 1 |
Extended properties
| Name | Value |
| MS_Description | AFTER INSERT trigger that inserts a row in the TransactionHistory table. |
SQL
SET ANSI_NULLS ON SET QUOTED_IDENTIFIER 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 EXEC sp_addextendedproperty N'MS_Description', N'AFTER INSERT trigger that inserts a row in the TransactionHistory table.', 'SCHEMA', N'Production', 'TABLE', N'WorkOrder', 'TRIGGER', N'iWorkOrder' GO |
See also