Northwind Database (Document! X Sample)
Sales.SalesOrderHeader Table
AdventureWorks Database > Sales Schema : Sales.SalesOrderHeader Table
Description
General sales order information.
Properties
Creation Date27/10/2017 14:33
File GroupPRIMARY
Text File Group
System Object
Published for Replication
Rows31465
Data Space Used5,480.00 KB
Index Space Used2,728.00 KB
Columns
 Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
Primary Key Primary key.Integer4   
 Incremental number to track changes to the sales order over time.UnsignedTinyInt1 
((0))
 
 Dates the sales order was created.DBTimeStamp4 
(getdate())
 
 Date the order is due to the customer.DBTimeStamp4   
 Date the order was shipped to the customer.DBTimeStamp4  
 Order current status. 1 = In process; 2 = Approved; 3 = Backordered; 4 = Rejected; 5 = Shipped; 6 = CancelledUnsignedTinyInt1 
((1))
 
 0 = Order placed by sales person. 1 = Order placed online by customer.dbo.Flag1 
((1))
 
 Unique sales order identification number.VarWChar25  
(isnull(N'SO'+CONVERT([nvarchar](23),[SalesOrderID]),N'*** ERROR ***'))
 Customer purchase order number reference. dbo.OrderNumber25  
 Financial accounting number reference.dbo.AccountNumber15  
 Customer identification number. Foreign key to Customer.BusinessEntityID.Integer4   
 Sales person who created the sales order. Foreign key to SalesPerson.BusinessEntityID.Integer4  
 Territory in which the sale was made. Foreign key to SalesTerritory.SalesTerritoryID.Integer4  
 Customer billing address. Foreign key to Address.AddressID.Integer4   
 Customer shipping address. Foreign key to Address.AddressID.Integer4   
 Shipping method. Foreign key to ShipMethod.ShipMethodID.Integer4   
 Credit card identification number. Foreign key to CreditCard.CreditCardID.Integer4  
 Approval code provided by the credit card company.VarChar15  
 Currency exchange rate used. Foreign key to CurrencyRate.CurrencyRateID.Integer4  
 Sales subtotal. Computed as SUM(SalesOrderDetail.LineTotal)for the appropriate SalesOrderID.Currency8 
((0.00))
 
 Tax amount.Currency8 
((0.00))
 
 Shipping cost.Currency8 
((0.00))
 
 Total due from customer. Computed as Subtotal + TaxAmt + Freight.Currency8  
(isnull(([SubTotal]+[TaxAmt])+[Freight],(0)))
 Sales representative comments.VarWChar128  
 ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.GUID16 
(newid())
 
 Date and time the record was last updated.DBTimeStamp4 
(getdate())
 
Indexes
IndexDescriptionPrimaryUnique
Unique nonclustered index. Used to support replication samples. 
Unique nonclustered index. 
Nonclustered index.  
Nonclustered index.  
Primary key (clustered) constraint
Check Constraints
NameDescriptionExpression
Check constraint [DueDate] >= [OrderDate]
([DueDate]>=[OrderDate])
Check constraint [Freight] >= (0.00)
([Freight]>=(0.00))
Check constraint [ShipDate] >= [OrderDate] OR [ShipDate] IS NULL
([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL)
Check constraint [Status] BETWEEN (0) AND (8)
([Status]>=(0) AND [Status]<=(8))
Check constraint [SubTotal] >= (0.00)
([SubTotal]>=(0.00))
Check constraint [TaxAmt] >= (0.00)
([TaxAmt]>=(0.00))
Triggers
TriggerDescription
AFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the SalesOrderHeader table.Updates the SalesYTD column in the SalesPerson and SalesTerritory tables.
Relationships
RelationshipDescription
Foreign key constraint referencing Address.AddressID.
Foreign key constraint referencing Address.AddressID.
Foreign key constraint referencing CreditCard.CreditCardID.
Foreign key constraint referencing CurrencyRate.CurrencyRateID.
Foreign key constraint referencing Customer.CustomerID.
Foreign key constraint referencing SalesPerson.SalesPersonID.
Foreign key constraint referencing SalesTerritory.TerritoryID.
Foreign key constraint referencing ShipMethod.ShipMethodID.
Objects that depend on Sales.SalesOrderHeader
 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.2
Sales.SalesOrderDetail tableSales.SalesOrderDetailTableIndividual products associated with a specific sales order. See SalesOrderHeader.1
Sales.SalesOrderHeaderSalesReason tableSales.SalesOrderHeaderSalesReasonTableCross-reference table mapping sales orders to sales reason codes.1
uSalesOrderHeader triggeruSalesOrderHeaderTriggerAFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the SalesOrderHeader table.Updates the SalesYTD column in the SalesPerson and SalesTerritory tables.1
Sales.vSalesPersonSalesByFiscalYears viewSales.vSalesPersonSalesByFiscalYearsViewUses PIVOT to return aggregated sales information for each sales representative.1
Objects that Sales.SalesOrderHeader depends on
 Database ObjectObject TypeDescriptionDep Level
dbo.AccountNumber datatypedbo.AccountNumberUser Defined Data Type 1
Person.Address tablePerson.AddressTableStreet address information for customers, employees, and vendors.1
Person.BusinessEntity tablePerson.BusinessEntityTableSource of the ID that connects vendors, customers, and employees with address and contact information.3
Sales.CreditCard tableSales.CreditCardTableCustomer credit card information.1
Sales.Currency tableSales.CurrencyTableLookup table containing standard ISO currencies.2
Sales.CurrencyRate tableSales.CurrencyRateTableCurrency exchange rates.1
Sales.Customer tableSales.CustomerTableCurrent customer information. Also see the Person and Store tables.1
HumanResources.Employee tableHumanResources.EmployeeTableEmployee information such as salary, department, and title.2
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.2
dbo.Flag datatypedbo.FlagUser Defined Data Type 1
dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 3
dbo.OrderNumber datatypedbo.OrderNumberUser Defined Data Type 1
Person.Person tablePerson.PersonTableHuman beings involved with AdventureWorks: employees, customer contacts, and vendor contacts.2
Sales.SalesPerson tableSales.SalesPersonTableSales representative current information.1
Sales.SalesTerritory tableSales.SalesTerritoryTableSales territory lookup table.1
Purchasing.ShipMethod tablePurchasing.ShipMethodTableShipping company lookup table.1
Person.StateProvince tablePerson.StateProvinceTableState and province lookup table.2
Sales.Store tableSales.StoreTableCustomers (resellers) of Adventure Works products.2
dbo.ufnGetAccountingEndDate functiondbo.ufnGetAccountingEndDateUser Defined FunctionScalar function used in the uSalesOrderHeader trigger to set the starting account date.1
dbo.ufnGetAccountingStartDate functiondbo.ufnGetAccountingStartDateUser Defined FunctionScalar function used in the uSalesOrderHeader trigger to set the ending account date.1
dbo.ufnLeadingZeros functiondbo.ufnLeadingZerosUser Defined FunctionScalar function used by the Sales.Customer table to help set the account number.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.1
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.1
SQL
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE TABLE [Sales].[SalesOrderHeader](
    [SalesOrderID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    [RevisionNumber] [tinyint] NOT NULL,
    [OrderDate] [datetime] NOT NULL,
    [DueDate] [datetime] NOT NULL,
    [ShipDate] [datetime] NULL,
    [Status] [tinyint] NOT NULL,
    [OnlineOrderFlag] [dbo].[Flag] NOT NULL,
    [SalesOrderNumber]  AS (isnull(N'SO'+CONVERT([nvarchar](23),[SalesOrderID]),N'*** ERROR ***')),
    [PurchaseOrderNumber] [dbo].[OrderNumber] NULL,
    [AccountNumber] [dbo].[AccountNumber] NULL,
    [CustomerID] [int] NOT NULL,
    [SalesPersonID] [int] NULL,
    [TerritoryID] [int] NULL,
    [BillToAddressID] [int] NOT NULL,
    [ShipToAddressID] [int] NOT NULL,
    [ShipMethodID] [int] NOT NULL,
    [CreditCardID] [int] NULL,
    [CreditCardApprovalCode] [varchar](15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [CurrencyRateID] [int] NULL,
    [SubTotal] [money] NOT NULL,
    [TaxAmt] [money] NOT NULL,
    [Freight] [money] NOT NULL,
    [TotalDue]  AS (isnull(([SubTotal]+[TaxAmt])+[Freight],(0))),
    [Comment] [nvarchar](128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_SalesOrderHeader_SalesOrderID] PRIMARY KEY CLUSTERED 
(
    [SalesOrderID] 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 [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_RevisionNumber]  DEFAULT ((0)) FOR [RevisionNumber]
ALTER TABLE [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_OrderDate]  DEFAULT (getdate()) FOR [OrderDate]
ALTER TABLE [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_Status]  DEFAULT ((1)) FOR [Status]
ALTER TABLE [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_OnlineOrderFlag]  DEFAULT ((1)) FOR [OnlineOrderFlag]
ALTER TABLE [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_SubTotal]  DEFAULT ((0.00)) FOR [SubTotal]
ALTER TABLE [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_TaxAmt]  DEFAULT ((0.00)) FOR [TaxAmt]
ALTER TABLE [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_Freight]  DEFAULT ((0.00)) FOR [Freight]
ALTER TABLE [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_rowguid]  DEFAULT (newid()) FOR [rowguid]
ALTER TABLE [Sales].[SalesOrderHeader] ADD  CONSTRAINT [DF_SalesOrderHeader_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID] FOREIGN KEY([BillToAddressID])
REFERENCES [Person].[Address] ([AddressID])
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeader_Address_ShipToAddressID] FOREIGN KEY([ShipToAddressID])
REFERENCES [Person].[Address] ([AddressID])
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Address_ShipToAddressID]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeader_CreditCard_CreditCardID] FOREIGN KEY([CreditCardID])
REFERENCES [Sales].[CreditCard] ([CreditCardID])
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_CreditCard_CreditCardID]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeader_CurrencyRate_CurrencyRateID] FOREIGN KEY([CurrencyRateID])
REFERENCES [Sales].[CurrencyRate] ([CurrencyRateID])
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_CurrencyRate_CurrencyRateID]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeader_Customer_CustomerID] FOREIGN KEY([CustomerID])
REFERENCES [Sales].[Customer] ([CustomerID])
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Customer_CustomerID]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] FOREIGN KEY([SalesPersonID])
REFERENCES [Sales].[SalesPerson] ([BusinessEntityID])
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] FOREIGN KEY([TerritoryID])
REFERENCES [Sales].[SalesTerritory] ([TerritoryID])
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY([ShipMethodID])
REFERENCES [Purchasing].[ShipMethod] ([ShipMethodID])
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderHeader_DueDate] CHECK  (([DueDate]>=[OrderDate]))
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [CK_SalesOrderHeader_DueDate]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderHeader_Freight] CHECK  (([Freight]>=(0.00)))
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [CK_SalesOrderHeader_Freight]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderHeader_ShipDate] CHECK  (([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL))
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [CK_SalesOrderHeader_ShipDate]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderHeader_Status] CHECK  (([Status]>=(0) AND [Status]<=(8)))
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [CK_SalesOrderHeader_Status]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderHeader_SubTotal] CHECK  (([SubTotal]>=(0.00)))
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [CK_SalesOrderHeader_SubTotal]
ALTER TABLE [Sales].[SalesOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderHeader_TaxAmt] CHECK  (([TaxAmt]>=(0.00)))
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [CK_SalesOrderHeader_TaxAmt]
See Also

Related Objects

Sales Schema
AdventureWorks Database