# Trigger: iWorkOrder

## Properties

Property | Value
--- | ---
Trigger | iWorkOrder
ID | 1739153241
Owner | dbo
Schema | Production
For Object | WorkOrder
Disabled |
Is Not For Replication |
Trigger Type Description | SQL TRIGGER
ANSI NULLS |
QUOTED IDENTIFIER |
Encrypted |
MS Shipped |
Execute As | Caller
Modify Date | 8/8/2010 5:23:44 PM
Creation Date | 8/8/2010 5:23:44 PM

## Extended Properties

Name | Value
--- | ---
MS_Description | AFTER INSERT trigger that inserts a row in the TransactionHistory table. mobi

## Trigger Type

Is After Trigger | Is Instead Of | Insert Trigger | Update Trigger | Delete Trigger
--- | --- | --- | --- | ---

## First / Last Trigger

First Delete Trigger | First Insert Trigger | First Update Trigger | Last Delete Trigger | Last Insert Trigger | Last Update Trigger
--- | --- | --- | --- | --- | ---

## Objects that depend on [iWorkOrder]

- iWorkOrder

## Objects on which [iWorkOrder] depends

- iWorkOrder
  - Production.WorkOrder
    - Production.TransactionHistory
      - Production.Product
        - Production.ProductSubcategory
          - Production.ProductCategory
            - dbo.Name
        - Production.UnitMeasure
        - Production.ProductModel
          - Production.ProductDescriptionSchemaCollection
          - Production.ManuInstructionsSchemaCollection
        - dbo.Flag
      - datePS
        - dataPF1
    - Production.ScrapReason
    - dbo.uspLogError
      - dbo.ErrorLog
      - dbo.uspPrintError

## SQL

Script
SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 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]; IF @@TRANCOUNT > 0 BEGIN ROLLBACK TRANSACTION; END EXECUTE [dbo].[uspLogError]; END CATCH; END; EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'AFTER INSERT trigger that inserts a row in the TransactionHistory table. mobi' , @level0type=N'SCHEMA',@level0name=N'Production', @level1type=N'TABLE',@level1name=N'WorkOrder', @level2type=N'TRIGGER',@level2name=N'iWorkOrder'

#### See also

List of Triggers