AdventureWorks
Purchasing.PurchaseOrderHeader Table
Description
General purchase order information. See PurchaseOrderDetail.
Properties
Creation Date08/01/2010 08:40
File GroupPRIMARY
Text File Group
System Object
Published for Replication
Rows4012
Data Space Used336.00 KB
Index Space Used144.00 KB
Columns
 Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
Primary Key PurchaseOrderIDPrimary key.int4   
 RevisionNumberIncremental number to track changes to the purchase order over time.tinyint1 
((0))
 
 StatusOrder current status. 1 = Pending; 2 = Approved; 3 = Rejected; 4 = Completetinyint1 
((1))
 
 EmployeeIDEmployee who created the purchase order. Foreign key to Employee.EmployeeID.int4   
 VendorIDVendor with whom the purchase order is placed. Foreign key to Vendor.VendorID.int4   
 ShipMethodIDShipping method. Foreign key to ShipMethod.ShipMethodID.int4   
 OrderDatePurchase order creation date.datetime4 
(getdate())
 
 ShipDateEstimated shipment date from the vendor.datetime4  
 SubTotalPurchase order subtotal. Computed as SUM(PurchaseOrderDetail.LineTotal)for the appropriate PurchaseOrderID.money8 
((0.00))
 
 TaxAmtTax amount.money8 
((0.00))
 
 FreightShipping cost.money8 
((0.00))
 
 TotalDueTotal due to vendor. Computed as Subtotal + TaxAmt + Freight.money8  
(isnull(([SubTotal]+[TaxAmt])+[Freight],(0)))
 ModifiedDateDate and time the record was last updated.datetime4 
(getdate())
 
Indexes
IndexDescriptionPrimaryUnique
IX_PurchaseOrderHeader_EmployeeIDNonclustered index.  
IX_PurchaseOrderHeader_VendorIDNonclustered index.  
PK_PurchaseOrderHeader_PurchaseOrderIDPrimary key (clustered) constraint
Check Constraints
NameDescriptionExpression
CK_PurchaseOrderHeader_FreightCheck constraint [Freight] >= (0.00)
([Freight]>=(0.00))
CK_PurchaseOrderHeader_ShipDateCheck constraint [ShipDate] >= [OrderDate] OR [ShipDate] IS NULL
([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL)
CK_PurchaseOrderHeader_StatusCheck constraint [Status] BETWEEN (1) AND (4)
([Status]>=(1) AND [Status]<=(4))
CK_PurchaseOrderHeader_SubTotalCheck constraint [SubTotal] >= (0.00)
([SubTotal]>=(0.00))
CK_PurchaseOrderHeader_TaxAmtCheck constraint [TaxAmt] >= (0.00)
([TaxAmt]>=(0.00))
Triggers
TriggerDescription
uPurchaseOrderHeaderAFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the PurchaseOrderHeader table.
Relationships
RelationshipDescription
FK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderIDForeign key constraint referencing PurchaseOrderHeader.PurchaseOrderID.
FK_PurchaseOrderHeader_Employee_EmployeeIDForeign key constraint referencing Employee.EmployeeID.
FK_PurchaseOrderHeader_ShipMethod_ShipMethodIDForeign key constraint referencing ShipMethod.ShipMethodID.
FK_PurchaseOrderHeader_Vendor_VendorIDForeign key constraint referencing Vendor.VendorID.
Objects that depend on Purchasing.PurchaseOrderHeader
 Database ObjectObject TypeDescriptionDep Level
iPurchaseOrderDetail triggeriPurchaseOrderDetailTriggerAFTER INSERT trigger that inserts a row in the TransactionHistory table and updates the PurchaseOrderHeader.SubTotal column.2
Purchasing.PurchaseOrderDetail tablePurchasing.PurchaseOrderDetailTableIndividual products associated with a specific purchase order. See PurchaseOrderHeader.1
uPurchaseOrderDetail triggeruPurchaseOrderDetailTriggerAFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in PurchaseOrderDetail and updates the PurchaseOrderHeader.SubTotal column.2
uPurchaseOrderHeader triggeruPurchaseOrderHeaderTriggerAFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the PurchaseOrderHeader table.1
Objects that Purchasing.PurchaseOrderHeader depends on
 Database ObjectObject TypeDescriptionDep Level
dbo.AccountNumber datatypedbo.AccountNumberUser Defined Data Type 2
Person.Contact tablePerson.ContactTableNames of each employee, customer contact, and vendor contact.2
HumanResources.Employee tableHumanResources.EmployeeTableEmployee information such as salary, department, and title.1
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
dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 3
dbo.Phone datatypedbo.PhoneUser Defined Data Type 3
Purchasing.ShipMethod tablePurchasing.ShipMethodTableShipping company lookup table.1
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
Purchasing.Vendor tablePurchasing.VendorTableCompanies from whom Adventure Works Cycles purchases parts or other goods.1
SQL
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE TABLE [Purchasing].[PurchaseOrderHeader](
	[PurchaseOrderID] [int] IDENTITY(1,1) NOT NULL,
	[RevisionNumber] [tinyint] NOT NULL,
	[Status] [tinyint] NOT NULL,
	[EmployeeID] [int] NOT NULL,
	[VendorID] [int] NOT NULL,
	[ShipMethodID] [int] NOT NULL,
	[OrderDate] [datetime] NOT NULL,
	[ShipDate] [datetime] NULL,
	[SubTotal] [money] NOT NULL,
	[TaxAmt] [money] NOT NULL,
	[Freight] [money] NOT NULL,
	[TotalDue]  AS (isnull(([SubTotal]+[TaxAmt])+[Freight],(0))) PERSISTED NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_PurchaseOrderHeader_PurchaseOrderID] PRIMARY KEY CLUSTERED 
(
	[PurchaseOrderID] 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 [Purchasing].[PurchaseOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_PurchaseOrderHeader_Employee_EmployeeID] FOREIGN KEY([EmployeeID])
REFERENCES [Employee] ([EmployeeID])
ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_Employee_EmployeeID]
ALTER TABLE [Purchasing].[PurchaseOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_PurchaseOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY([ShipMethodID])
REFERENCES [ShipMethod] ([ShipMethodID])
ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_ShipMethod_ShipMethodID]
ALTER TABLE [Purchasing].[PurchaseOrderHeader]  WITH CHECK ADD  CONSTRAINT [FK_PurchaseOrderHeader_Vendor_VendorID] FOREIGN KEY([VendorID])
REFERENCES [Vendor] ([VendorID])
ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_Vendor_VendorID]
ALTER TABLE [Purchasing].[PurchaseOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_PurchaseOrderHeader_Freight] CHECK  (([Freight]>=(0.00)))
ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [CK_PurchaseOrderHeader_Freight]
ALTER TABLE [Purchasing].[PurchaseOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_PurchaseOrderHeader_ShipDate] CHECK  (([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL))
ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [CK_PurchaseOrderHeader_ShipDate]
ALTER TABLE [Purchasing].[PurchaseOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_PurchaseOrderHeader_Status] CHECK  (([Status]>=(1) AND [Status]<=(4)))
ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [CK_PurchaseOrderHeader_Status]
ALTER TABLE [Purchasing].[PurchaseOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_PurchaseOrderHeader_SubTotal] CHECK  (([SubTotal]>=(0.00)))
ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [CK_PurchaseOrderHeader_SubTotal]
ALTER TABLE [Purchasing].[PurchaseOrderHeader]  WITH CHECK ADD  CONSTRAINT [CK_PurchaseOrderHeader_TaxAmt] CHECK  (([TaxAmt]>=(0.00)))
ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [CK_PurchaseOrderHeader_TaxAmt]
ALTER TABLE [Purchasing].[PurchaseOrderHeader] ADD  CONSTRAINT [DF_PurchaseOrderHeader_RevisionNumber]  DEFAULT ((0)) FOR [RevisionNumber]
ALTER TABLE [Purchasing].[PurchaseOrderHeader] ADD  CONSTRAINT [DF_PurchaseOrderHeader_Status]  DEFAULT ((1)) FOR [Status]
ALTER TABLE [Purchasing].[PurchaseOrderHeader] ADD  CONSTRAINT [DF_PurchaseOrderHeader_OrderDate]  DEFAULT (getdate()) FOR [OrderDate]
ALTER TABLE [Purchasing].[PurchaseOrderHeader] ADD  CONSTRAINT [DF_PurchaseOrderHeader_SubTotal]  DEFAULT ((0.00)) FOR [SubTotal]
ALTER TABLE [Purchasing].[PurchaseOrderHeader] ADD  CONSTRAINT [DF_PurchaseOrderHeader_TaxAmt]  DEFAULT ((0.00)) FOR [TaxAmt]
ALTER TABLE [Purchasing].[PurchaseOrderHeader] ADD  CONSTRAINT [DF_PurchaseOrderHeader_Freight]  DEFAULT ((0.00)) FOR [Freight]
ALTER TABLE [Purchasing].[PurchaseOrderHeader] ADD  CONSTRAINT [DF_PurchaseOrderHeader_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
See Also

Related Objects

Purchasing Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.