AdventureWorks
Sales.SalesOrderDetail Table
Description
Individual products associated with a specific sales order. See SalesOrderHeader.
Properties
Creation Date08/01/2010 08:40
File GroupPRIMARY
Text File Group
System Object
Published for Replication
Rows121317
Data Space Used9,864.00 KB
Index Space Used5,144.00 KB
Columns
 Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
Primary Key SalesOrderIDPrimary key. Foreign key to SalesOrderHeader.SalesOrderID.int4   
Primary Key SalesOrderDetailIDPrimary key. One incremental unique number per product sold.int4   
 CarrierTrackingNumberShipment tracking number supplied by the shipper.nvarchar25  
 OrderQtyQuantity ordered per product.smallint2   
 ProductIDProduct sold to customer. Foreign key to Product.ProductID.int4   
 SpecialOfferIDPromotional code. Foreign key to SpecialOffer.SpecialOfferID.int4   
 UnitPriceSelling price of a single product.money8   
 UnitPriceDiscountDiscount amount.money8 
((0.0))
 
 LineTotalPer product subtotal. Computed as UnitPrice * (1 - UnitPriceDiscount) * OrderQty.numeric9 (38,6)  
(isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0)))
 rowguidROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.uniqueidentifier16 
(newid())
 
 ModifiedDateDate and time the record was last updated.datetime4 
(getdate())
 
Indexes
IndexDescriptionPrimaryUnique
AK_SalesOrderDetail_rowguidUnique nonclustered index. Used to support replication samples. 
IX_SalesOrderDetail_ProductIDNonclustered index.  
PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailIDPrimary key (clustered) constraint
Check Constraints
NameDescriptionExpression
CK_SalesOrderDetail_OrderQtyCheck constraint [OrderQty] > (0)
([OrderQty]>(0))
CK_SalesOrderDetail_UnitPriceCheck constraint [UnitPrice] >= (0.00)
([UnitPrice]>=(0.00))
CK_SalesOrderDetail_UnitPriceDiscountCheck constraint [UnitPriceDiscount] >= (0.00)
([UnitPriceDiscount]>=(0.00))
Triggers
TriggerDescription
iduSalesOrderDetailAFTER INSERT, DELETE, UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in SalesOrderDetail and updates the SalesOrderHeader.SubTotal column.
Relationships
RelationshipDescription
FK_SalesOrderDetail_SalesOrderHeader_SalesOrderIDForeign key constraint referencing SalesOrderHeader.PurchaseOrderID.
FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductIDForeign key constraint referencing SpecialOfferProduct.SpecialOfferIDProductID.
Objects that depend on Sales.SalesOrderDetail
 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.1
Objects that Sales.SalesOrderDetail depends on
 Database ObjectObject TypeDescriptionDep Level
dbo.AccountNumber datatypedbo.AccountNumberUser Defined Data Type 2
Person.Address tablePerson.AddressTableStreet address information for customers, employees, and vendors.2
Person.Contact tablePerson.ContactTableNames of each employee, customer contact, and vendor contact.2
Person.CountryRegion tablePerson.CountryRegionTableLookup table containing the ISO standard codes for countries and regions.4
Sales.CreditCard tableSales.CreditCardTableCustomer credit card information.2
Sales.Currency tableSales.CurrencyTableLookup table containing standard ISO currencies.3
Sales.CurrencyRate tableSales.CurrencyRateTableCurrency exchange rates.2
Sales.Customer tableSales.CustomerTableCurrent customer information. Also see the Individual and Store tables.2
HumanResources.Employee tableHumanResources.EmployeeTableEmployee information such as salary, department, and title.3
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 2
Sales.Individual tableSales.IndividualTableDemographic data about customers that purchase Adventure Works products online.1
dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 3
dbo.OrderNumber datatypedbo.OrderNumberUser Defined Data Type 2
dbo.Phone datatypedbo.PhoneUser Defined Data Type 3
Production.Product tableProduction.ProductTableProducts sold or used in the manfacturing of sold products.2
Production.ProductCategory tableProduction.ProductCategoryTableHigh-level product categorization.4
Production.ProductModel tableProduction.ProductModelTableProduct model classification.3
Production.ProductSubcategory tableProduction.ProductSubcategoryTableProduct subcategories. See ProductCategory table.3
Sales.SalesOrderHeader tableSales.SalesOrderHeaderTableGeneral sales order information.1
Sales.SalesPerson tableSales.SalesPersonTableSales representative current information.2
Sales.SalesTerritory tableSales.SalesTerritoryTableSales territory lookup table.2
Purchasing.ShipMethod tablePurchasing.ShipMethodTableShipping company lookup table.2
Sales.SpecialOffer tableSales.SpecialOfferTableSale discounts lookup table.2
Sales.SpecialOfferProduct tableSales.SpecialOfferProductTableCross-reference table mapping products to special offer discounts.1
Person.StateProvince tablePerson.StateProvinceTableState and province lookup table.3
Sales.Store tableSales.StoreTableCustomers (resellers) of Adventure Works products.2
Production.TransactionHistory tableProduction.TransactionHistoryTableRecord of each purchase order, sales order, or work order transaction year to date.1
dbo.ufnGetAccountingEndDate functiondbo.ufnGetAccountingEndDateUser Defined FunctionScalar function used in the uSalesOrderHeader trigger to set the starting account date.2
dbo.ufnGetAccountingStartDate functiondbo.ufnGetAccountingStartDateUser Defined FunctionScalar function used in the uSalesOrderHeader trigger to set the ending account date.2
dbo.ufnLeadingZeros functiondbo.ufnLeadingZerosUser Defined FunctionScalar function used by the Sales.Customer table to help set the account number.3
Production.UnitMeasure tableProduction.UnitMeasureTableUnit of measure lookup table.3
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].[SalesOrderDetail](
	[SalesOrderID] [int] NOT NULL,
	[SalesOrderDetailID] [int] IDENTITY(1,1) NOT NULL,
	[CarrierTrackingNumber] [nvarchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[OrderQty] [smallint] NOT NULL,
	[ProductID] [int] NOT NULL,
	[SpecialOfferID] [int] NOT NULL,
	[UnitPrice] [money] NOT NULL,
	[UnitPriceDiscount] [money] NOT NULL,
	[LineTotal]  AS (isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0))),
	[rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID] PRIMARY KEY CLUSTERED 
(
	[SalesOrderID] ASC,
	[SalesOrderDetailID] 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].[SalesOrderDetail]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID] FOREIGN KEY([SalesOrderID])
REFERENCES [SalesOrderHeader] ([SalesOrderID])
ON DELETE CASCADE
ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID]
ALTER TABLE [Sales].[SalesOrderDetail]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID] FOREIGN KEY([SpecialOfferID], [ProductID])
REFERENCES [SpecialOfferProduct] ([SpecialOfferID], [ProductID])
ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID]
ALTER TABLE [Sales].[SalesOrderDetail]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderDetail_OrderQty] CHECK  (([OrderQty]>(0)))
ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [CK_SalesOrderDetail_OrderQty]
ALTER TABLE [Sales].[SalesOrderDetail]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderDetail_UnitPrice] CHECK  (([UnitPrice]>=(0.00)))
ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [CK_SalesOrderDetail_UnitPrice]
ALTER TABLE [Sales].[SalesOrderDetail]  WITH CHECK ADD  CONSTRAINT [CK_SalesOrderDetail_UnitPriceDiscount] CHECK  (([UnitPriceDiscount]>=(0.00)))
ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [CK_SalesOrderDetail_UnitPriceDiscount]
ALTER TABLE [Sales].[SalesOrderDetail] ADD  CONSTRAINT [DF_SalesOrderDetail_UnitPriceDiscount]  DEFAULT ((0.0)) FOR [UnitPriceDiscount]
ALTER TABLE [Sales].[SalesOrderDetail] ADD  CONSTRAINT [DF_SalesOrderDetail_rowguid]  DEFAULT (newid()) FOR [rowguid]
ALTER TABLE [Sales].[SalesOrderDetail] ADD  CONSTRAINT [DF_SalesOrderDetail_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
See Also

Related Objects

Sales Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.