Editing Production.WorkOrder (table)

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 2: Line 2:
  
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
|- valign="top"
+
|-
 
| '''Table
 
| '''Table
 
| Production.WorkOrder
 
| Production.WorkOrder
|- valign="top"
+
|-
| '''Description
 
| Manufacturing work orders.
 
 
|}
 
|}
  
=== Columns ===
+
 
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
|- style="background:silver"
Line 17: Line 15:
 
| '''Nullable
 
| '''Nullable
 
| '''Default
 
| '''Default
| '''Description
+
| '''PK
 
+
| '''Index
|- valign="top"
+
 +
|-
 
| WorkOrderID
 
| WorkOrderID
 
| int
 
| int
 
| not null
 
| not null
 
|  
 
|  
| Primary key for WorkOrder records.
+
| PK_WorkOrder_WorkOrderID
|- valign="top"
+
|
 +
|-
 
| ProductID
 
| ProductID
 
| int
 
| int
 
| not null
 
| not null
 
|  
 
|  
| Product identification number. Foreign key to Product.ProductID.
+
|  
|- valign="top"
+
| IX_WorkOrder_ProductID
 +
|-
 
| OrderQty
 
| OrderQty
 
| int
 
| int
 
| not null
 
| not null
 
|  
 
|  
| Product quantity to build.
+
|  
|- valign="top"
+
|
 +
|-
 
| StockedQty
 
| StockedQty
 
|  
 
|  
 
|  
 
|  
 
|  
 
|  
| Quantity built and put in inventory.
+
|  
|- valign="top"
+
|
 +
|-
 
| ScrappedQty
 
| ScrappedQty
 
| smallint
 
| smallint
 
| not null
 
| not null
 
|  
 
|  
| Quantity that failed inspection.
+
|  
|- valign="top"
+
|
 +
|-
 
| StartDate
 
| StartDate
 
| datetime
 
| datetime
 
| not null
 
| not null
 
|  
 
|  
| Work order start date.
+
|  
|- valign="top"
+
|
 +
|-
 
| EndDate
 
| EndDate
 
| datetime
 
| datetime
 
| null
 
| null
 
|  
 
|  
| Work order end date.
+
|  
|- valign="top"
+
|
 +
|-
 
| DueDate
 
| DueDate
 
| datetime
 
| datetime
 
| not null
 
| not null
 
|  
 
|  
| Work order due date.
+
|  
|- valign="top"
+
|
 +
|-
 
| ScrapReasonID
 
| ScrapReasonID
 
| smallint
 
| smallint
 
| null
 
| null
 
|  
 
|  
| Reason for inspection failure.
+
|  
|- valign="top"
+
| IX_WorkOrder_ScrapReasonID
 +
|-
 
| ModifiedDate
 
| ModifiedDate
 
| datetime
 
| datetime
 
| not null
 
| not null
 
| (getdate())
 
| (getdate())
| Date and time the record was last updated.
 
|}
 
 
=== Primary Key ===
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
| '''Primary Key
 
| '''Columns
 
|- valign="top"
 
| PK_WorkOrder_WorkOrderID
 
| WorkOrderID
 
|}
 
 
=== Indexes ===
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
| '''Index
 
| '''Type
 
| '''Columns
 
 
|- valign="top"
 
| IX_WorkOrder_ProductID
 
 
|  
 
|  
| ProductID
 
|- valign="top"
 
| IX_WorkOrder_ScrapReasonID
 
 
|  
 
|  
| ScrapReasonID
 
 
|}
 
|}
  
=== Check Constraints ===
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
| '''Check Constraint
 
| '''Expression
 
| '''Description
 
  
|- valign="top"
 
| CK_WorkOrder_EndDate
 
| ([EndDate]>=[StartDate] OR [EndDate] IS NULL)
 
| Check constraint [EndDate] >= [StartDate] OR [EndDate] IS NULL
 
|- valign="top"
 
| CK_WorkOrder_OrderQty
 
| ([OrderQty]>(0))
 
| Check constraint [OrderQty] > (0)
 
|- valign="top"
 
| CK_WorkOrder_ScrappedQty
 
| ([ScrappedQty]>=(0))
 
| Check constraint [ScrappedQty] >= (0)
 
|}
 
  
=== Foreign Keys ===
 
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
|- style="background:silver"
Line 135: Line 97:
 
| '''Column
 
| '''Column
 
| '''Referenced Column
 
| '''Referenced Column
 
+
|- valign="top"
+
|-
 
| [[Production.Product_(table)|Production.Product]]
 
| [[Production.Product_(table)|Production.Product]]
 
| ProductID
 
| ProductID
 
| ProductID
 
| ProductID
|- valign="top"
+
|-
 
| [[Production.ScrapReason_(table)|Production.ScrapReason]]
 
| [[Production.ScrapReason_(table)|Production.ScrapReason]]
 
| ScrapReasonID
 
| ScrapReasonID
Line 146: Line 108:
 
|}
 
|}
  
=== Detail Tables ===
+
 
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
|- style="background:silver"
Line 152: Line 114:
 
| '''Column
 
| '''Column
 
| '''Referencing Column
 
| '''Referencing Column
 
+
|- valign="top"
+
|-
 
| [[Production.WorkOrderRouting_(table)|Production.WorkOrderRouting]]
 
| [[Production.WorkOrderRouting_(table)|Production.WorkOrderRouting]]
 
| WorkOrderID
 
| WorkOrderID
Line 159: Line 121:
 
|}
 
|}
  
=== Triggers ===
+
 
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
|- style="background:silver"
| '''Trigger
+
| '''Triggers
 
| '''Type
 
| '''Type
 
+
|- valign="top"
+
|-
 
| iWorkOrder
 
| iWorkOrder
 
| ON INSERT
 
| ON INSERT
|- valign="top"
+
|-
 
| uWorkOrder
 
| uWorkOrder
 
| ON UPDATE
 
| ON UPDATE
 
|}
 
|}
 
==== Trigger iWorkOrder ====
 
<pre>
 
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;
 
</pre>
 
 
==== Trigger uWorkOrder ====
 
<pre>
 
CREATE TRIGGER [Production].[uWorkOrder] ON [Production].[WorkOrder]
 
AFTER UPDATE AS
 
BEGIN
 
    DECLARE @Count int;
 
 
    SET @Count = @@ROWCOUNT;
 
    IF @Count = 0
 
        RETURN;
 
 
    SET NOCOUNT ON;
 
 
    BEGIN TRY
 
        IF UPDATE([ProductID]) OR UPDATE([OrderQty])
 
        BEGIN
 
            INSERT INTO [Production].[TransactionHistory](
 
                [ProductID]
 
                ,[ReferenceOrderID]
 
                ,[TransactionType]
 
                ,[TransactionDate]
 
                ,[Quantity])
 
            SELECT
 
                inserted.[ProductID]
 
                ,inserted.[WorkOrderID]
 
                ,'W'
 
                ,GETDATE()
 
                ,inserted.[OrderQty]
 
            FROM inserted;
 
        END;
 
    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;
 
</pre>
 
 
=== References ===
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
| '''Dependency Type
 
| '''Object Type
 
| '''Referenced Object
 
 
| '''Child Type
 
| '''Child Object
 
 
|- valign="top"
 
| Schema
 
| Schema
 
| [[Production_(schema)|Production]]
 
 
|
 
|
 
|- valign="top"
 
| Insert
 
| Table
 
| [[Production.TransactionHistory_(table)|Production.TransactionHistory]]
 
 
| Trigger
 
| iWorkOrder
 
|- valign="top"
 
| Insert
 
| Table
 
| [[Production.TransactionHistory_(table)|Production.TransactionHistory]]
 
 
| Trigger
 
| uWorkOrder
 
|- valign="top"
 
| Execute
 
| Procedure
 
| [[dbo.uspLogError_(procedure)|dbo.uspLogError]]
 
 
| Trigger
 
| iWorkOrder
 
|- valign="top"
 
| Execute
 
| Procedure
 
| [[dbo.uspLogError_(procedure)|dbo.uspLogError]]
 
 
| Trigger
 
| uWorkOrder
 
|- valign="top"
 
| Execute
 
| Procedure
 
| [[dbo.uspPrintError_(procedure)|dbo.uspPrintError]]
 
 
| Trigger
 
| iWorkOrder
 
|- valign="top"
 
| Execute
 
| Procedure
 
| [[dbo.uspPrintError_(procedure)|dbo.uspPrintError]]
 
 
| Trigger
 
| uWorkOrder
 
|}
 
 
 
 
== automatically generated ==
 
== automatically generated ==
  
Line 333: Line 141:
 
| Production.WorkOrder
 
| Production.WorkOrder
 
|- valign="top"
 
|- valign="top"
 +
 
| '''Description
 
| '''Description
 
| Manufacturing work orders.
 
| Manufacturing work orders.
 
|-
 
|-
 +
 
|}
 
|}
  
Line 457: Line 267:
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
|- style="background:silver"
 +
| '''Referenced Object
 +
| '''Object Type
 
| '''Dependency Type
 
| '''Dependency Type
| '''Object Type
+
| '''Referenced Object
 
 
 
| '''Child Type
 
| '''Child Object
 
 
 
 
|-
 
|-
| Schema
+
| [[Production.TransactionHistory_(table)|Production.TransactionHistory]]
| Schema
+
| Table
| [[Production_(schema)|Production]]
+
| Insert
 
 
|  
 
|  
 
 
|-
 
|-
| Insert
+
| [[Production.TransactionHistory_(table)|Production.TransactionHistory]]
 
| Table
 
| Table
| [[Production.TransactionHistory_(table)|Production.TransactionHistory]]
 
 
| Trigger
 
| iWorkOrder
 
|-
 
 
| Insert
 
| Insert
| Table
 
| [[Production.TransactionHistory_(table)|Production.TransactionHistory]]
 
 
| Trigger
 
| uWorkOrder
 
 
|-
 
|-
 +
| [[dbo.uspLogError_(procedure)|dbo.uspLogError]]
 +
| Procedure
 
| Execute
 
| Execute
 +
|-
 +
| [[dbo.uspLogError_(procedure)|dbo.uspLogError]]
 
| Procedure
 
| Procedure
| [[dbo.uspLogError_(procedure)|dbo.uspLogError]]
+
| Execute
 
 
| Trigger
 
| iWorkOrder
 
 
|-
 
|-
 +
| [[dbo.uspPrintError_(procedure)|dbo.uspPrintError]]
 +
| Procedure
 
| Execute
 
| Execute
| Procedure
 
| [[dbo.uspLogError_(procedure)|dbo.uspLogError]]
 
 
| Trigger
 
| uWorkOrder
 
 
|-
 
|-
| Execute
+
| [[dbo.uspPrintError_(procedure)|dbo.uspPrintError]]
 
| Procedure
 
| Procedure
| [[dbo.uspPrintError_(procedure)|dbo.uspPrintError]]
 
 
| Trigger
 
| uWorkOrder
 
|-
 
 
| Execute
 
| Execute
| Procedure
 
| [[dbo.uspPrintError_(procedure)|dbo.uspPrintError]]
 
 
| Trigger
 
| iWorkOrder
 
 
|}
 
|}

Please note that all contributions to dbscript Online Help may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Project:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)