Northwind Database (Document! X Sample)
AdventureWorks Database / Production Schema / Production.TransactionHistory Table
In This Topic
    Production.TransactionHistory Table
    In This Topic
    Description
    Record of each purchase order, sales order, or work order transaction year to date.
    Properties
    Creation Date27/10/2017 14:33
    File GroupPRIMARY
    Text File Group
    System Object
    Published for Replication
    Rows113443
    Data Space Used6,336.00 KB
    Index Space Used3,928.00 KB
    Columns
     Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
    Primary Key Primary key for TransactionHistory records.Integer4   
     Product identification number. Foreign key to Product.ProductID.Integer4   
     Purchase order, sales order, or work order identification number.Integer4   
     Line number associated with the purchase order, sales order, or work order.Integer4 
    ((0))
     
     Date and time of the transaction.DBTimeStamp4 
    (getdate())
     
     W = WorkOrder, S = SalesOrder, P = PurchaseOrderWChar1   
     Product quantity.Integer4   
     Product cost.Currency8   
     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 [TransactionType]='p' OR [TransactionType]='s' OR [TransactionType]='w' OR [TransactionType]='P' OR [TransactionType]='S' OR [TransactionType]='W')
    (upper([TransactionType])='P' OR upper([TransactionType])='S' OR upper([TransactionType])='W')
    Relationships
    RelationshipDescription
    Foreign key constraint referencing Product.ProductID.
    Objects that depend on Production.TransactionHistory
     Database ObjectObject TypeDescriptionDep Level
    iduSalesOrderDetail triggeriduSalesOrderDetailTriggerAFTER INSERT, DELETE, UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in SalesOrderDetail and updates the SalesOrderHeader.SubTotal column.3
    iPurchaseOrderDetail triggeriPurchaseOrderDetailTriggerAFTER INSERT trigger that inserts a row in the TransactionHistory table and updates the PurchaseOrderHeader.SubTotal column.3
    iWorkOrder triggeriWorkOrderTriggerAFTER INSERT trigger that inserts a row in the TransactionHistory table.1
    Purchasing.PurchaseOrderDetail tablePurchasing.PurchaseOrderDetailTableIndividual products associated with a specific purchase order. See PurchaseOrderHeader.2
    Sales.SalesOrderDetail tableSales.SalesOrderDetailTableIndividual products associated with a specific sales order. See SalesOrderHeader.2
    uPurchaseOrderDetail triggeruPurchaseOrderDetailTriggerAFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in PurchaseOrderDetail and updates the PurchaseOrderHeader.SubTotal column.3
    uWorkOrder triggeruWorkOrderTriggerAFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in the WorkOrder table.1
    Production.WorkOrder tableProduction.WorkOrderTableManufacturing work orders.1
    Production.WorkOrderRouting tableProduction.WorkOrderRoutingTableWork order details.1
    Objects that Production.TransactionHistory depends on
     Database ObjectObject TypeDescriptionDep Level
    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.UnitMeasure tableProduction.UnitMeasureTableUnit of measure lookup table.2
    SQL
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [Production].[TransactionHistory](
        [TransactionID] [int] IDENTITY(100000,1) NOT NULL,
        [ProductID] [int] NOT NULL,
        [ReferenceOrderID] [int] NOT NULL,
        [ReferenceOrderLineID] [int] NOT NULL,
        [TransactionDate] [datetime] NOT NULL,
        [TransactionType] [nchar](1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
        [Quantity] [int] NOT NULL,
        [ActualCost] [money] NOT NULL,
        [ModifiedDate] [datetime] NOT NULL,
     CONSTRAINT [PK_TransactionHistory_TransactionID] PRIMARY KEY CLUSTERED 
    (
        [TransactionID] 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].[TransactionHistory] ADD  CONSTRAINT [DF_TransactionHistory_ReferenceOrderLineID]  DEFAULT ((0)) FOR [ReferenceOrderLineID]
    ALTER TABLE [Production].[TransactionHistory] ADD  CONSTRAINT [DF_TransactionHistory_TransactionDate]  DEFAULT (getdate()) FOR [TransactionDate]
    ALTER TABLE [Production].[TransactionHistory] ADD  CONSTRAINT [DF_TransactionHistory_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
    ALTER TABLE [Production].[TransactionHistory]  WITH CHECK ADD  CONSTRAINT [FK_TransactionHistory_Product_ProductID] FOREIGN KEY([ProductID])
    REFERENCES [Production].[Product] ([ProductID])
    ALTER TABLE [Production].[TransactionHistory] CHECK CONSTRAINT [FK_TransactionHistory_Product_ProductID]
    ALTER TABLE [Production].[TransactionHistory]  WITH CHECK ADD  CONSTRAINT [CK_TransactionHistory_TransactionType] CHECK  ((upper([TransactionType])='P' OR upper([TransactionType])='S' OR upper([TransactionType])='W'))
    ALTER TABLE [Production].[TransactionHistory] CHECK CONSTRAINT [CK_TransactionHistory_TransactionType]
    See Also