Northwind Database (Document! X Sample)
AdventureWorks Database / Production Schema / Production.WorkOrder Table
In This Topic
    Production.WorkOrder Table
    In This Topic
    Description
    Manufacturing work orders.
    Properties
    Creation Date27/10/2017 14:33
    File GroupPRIMARY
    Text File Group
    System Object
    Published for Replication
    Rows72591
    Data Space Used4,224.00 KB
    Index Space Used2,088.00 KB
    Columns
     Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
    Primary Key Primary key for WorkOrder records.Integer4   
     Product identification number. Foreign key to Product.ProductID.Integer4   
     Product quantity to build.Integer4   
     Quantity built and put in inventory.Integer4  
    (isnull([OrderQty]-[ScrappedQty],(0)))
     Quantity that failed inspection.SmallInt2   
     Work order start date.DBTimeStamp4   
     Work order end date.DBTimeStamp4  
     Work order due date.DBTimeStamp4   
     Reason for inspection failure.SmallInt2  
     Date and time the record was last updated.DBTimeStamp4 
    (getdate())
     
    Indexes
    IndexDescriptionPrimaryUnique
    Nonclustered index.  
    Nonclustered index.  
    Primary key (clustered) constraint
    Check Constraints
    NameDescriptionExpression
    Check constraint [EndDate] >= [StartDate] OR [EndDate] IS NULL
    ([EndDate]>=[StartDate] OR [EndDate] IS NULL)
    Check constraint [OrderQty] > (0)
    ([OrderQty]>(0))
    Check constraint [ScrappedQty] >= (0)
    ([ScrappedQty]>=(0))
    Triggers
    TriggerDescription
    AFTER INSERT trigger that inserts a row in the TransactionHistory table.
    AFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in the WorkOrder table.
    Relationships
    RelationshipDescription
    Foreign key constraint referencing Product.ProductID.
    Foreign key constraint referencing ScrapReason.ScrapReasonID.
    Foreign key constraint referencing WorkOrder.WorkOrderID.
    Objects that depend on Production.WorkOrder
     Database ObjectObject TypeDescriptionDep Level
    iWorkOrder triggeriWorkOrderTriggerAFTER INSERT trigger that inserts a row in the TransactionHistory table.1
    uWorkOrder triggeruWorkOrderTriggerAFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in the WorkOrder table.1
    Production.WorkOrderRouting tableProduction.WorkOrderRoutingTableWork order details.1
    Objects that Production.WorkOrder depends on
     Database ObjectObject TypeDescriptionDep Level
    dbo.ErrorLog tabledbo.ErrorLogTableAudit table tracking errors in the the AdventureWorks database that are caught by the CATCH block of a TRY...CATCH construct. Data is inserted by stored procedure dbo.uspLogError when it is executed from inside the CATCH block of a TRY...CATCH construct.3
    dbo.Flag datatypedbo.FlagUser Defined Data Type 4
    dbo.Name datatypedbo.NameUser Defined Data Type 2
    Production.Product tableProduction.ProductTableProducts sold or used in the manfacturing of sold products.1
    Production.ProductCategory tableProduction.ProductCategoryTableHigh-level product categorization.3
    Production.ProductModel tableProduction.ProductModelTableProduct model classification.2
    Production.ProductSubcategory tableProduction.ProductSubcategoryTableProduct subcategories. See ProductCategory table.2
    Production.ScrapReason tableProduction.ScrapReasonTableManufacturing failure reasons lookup table.2
    Production.TransactionHistory tableProduction.TransactionHistoryTableRecord of each purchase order, sales order, or work order transaction year to date.1
    Production.UnitMeasure tableProduction.UnitMeasureTableUnit of measure lookup table.2
    dbo.uspLogError proceduredbo.uspLogErrorStored ProcedureLogs error information in the ErrorLog table about the error that caused execution to jump to the CATCH block of a TRY...CATCH construct. Should be executed from within the scope of a CATCH block otherwise it will return without inserting error information.2
    dbo.uspPrintError proceduredbo.uspPrintErrorStored ProcedurePrints error information about the error that caused execution to jump to the CATCH block of a TRY...CATCH construct. Should be executed from within the scope of a CATCH block otherwise it will return without printing any error information.2
    SQL
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [Production].[WorkOrder](
        [WorkOrderID] [int] IDENTITY(1,1) NOT NULL,
        [ProductID] [int] NOT NULL,
        [OrderQty] [int] NOT NULL,
        [StockedQty]  AS (isnull([OrderQty]-[ScrappedQty],(0))),
        [ScrappedQty] [smallint] NOT NULL,
        [StartDate] [datetime] NOT NULL,
        [EndDate] [datetime] NULL,
        [DueDate] [datetime] NOT NULL,
        [ScrapReasonID] [smallint] NULL,
        [ModifiedDate] [datetime] NOT NULL,
     CONSTRAINT [PK_WorkOrder_WorkOrderID] PRIMARY KEY CLUSTERED 
    (
        [WorkOrderID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    ALTER TABLE [Production].[WorkOrder] ADD  CONSTRAINT [DF_WorkOrder_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
    ALTER TABLE [Production].[WorkOrder]  WITH CHECK ADD  CONSTRAINT [FK_WorkOrder_Product_ProductID] FOREIGN KEY([ProductID])
    REFERENCES [Production].[Product] ([ProductID])
    ALTER TABLE [Production].[WorkOrder] CHECK CONSTRAINT [FK_WorkOrder_Product_ProductID]
    ALTER TABLE [Production].[WorkOrder]  WITH CHECK ADD  CONSTRAINT [FK_WorkOrder_ScrapReason_ScrapReasonID] FOREIGN KEY([ScrapReasonID])
    REFERENCES [Production].[ScrapReason] ([ScrapReasonID])
    ALTER TABLE [Production].[WorkOrder] CHECK CONSTRAINT [FK_WorkOrder_ScrapReason_ScrapReasonID]
    ALTER TABLE [Production].[WorkOrder]  WITH CHECK ADD  CONSTRAINT [CK_WorkOrder_EndDate] CHECK  (([EndDate]>=[StartDate] OR [EndDate] IS NULL))
    ALTER TABLE [Production].[WorkOrder] CHECK CONSTRAINT [CK_WorkOrder_EndDate]
    ALTER TABLE [Production].[WorkOrder]  WITH CHECK ADD  CONSTRAINT [CK_WorkOrder_OrderQty] CHECK  (([OrderQty]>(0)))
    ALTER TABLE [Production].[WorkOrder] CHECK CONSTRAINT [CK_WorkOrder_OrderQty]
    ALTER TABLE [Production].[WorkOrder]  WITH CHECK ADD  CONSTRAINT [CK_WorkOrder_ScrappedQty] CHECK  (([ScrappedQty]>=(0)))
    ALTER TABLE [Production].[WorkOrder] CHECK CONSTRAINT [CK_WorkOrder_ScrappedQty]
    See Also