Difference between revisions of "Purchasing.PurchaseOrderHeader (table)"
(2 intermediate revisions by the same user not shown) | |||
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 | ||
| Purchasing.PurchaseOrderHeader | | Purchasing.PurchaseOrderHeader | ||
Line 8: | Line 8: | ||
| '''Description | | '''Description | ||
| General purchase order information. See PurchaseOrderDetail. | | General purchase order information. See PurchaseOrderDetail. | ||
− | |||
|} | |} | ||
− | + | === 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 18: | Line 17: | ||
| '''Nullable | | '''Nullable | ||
| '''Default | | '''Default | ||
− | | '''Description | + | | '''Description |
− | + | ||
|- valign="top" | |- valign="top" | ||
| PurchaseOrderID | | PurchaseOrderID | ||
Line 25: | Line 24: | ||
| not null | | not null | ||
| | | | ||
− | | Primary key. | + | | Primary key. |
|- valign="top" | |- valign="top" | ||
| RevisionNumber | | RevisionNumber | ||
Line 31: | Line 30: | ||
| not null | | not null | ||
| ((0)) | | ((0)) | ||
− | | Incremental number to track changes to the purchase order over time. | + | | Incremental number to track changes to the purchase order over time. |
|- valign="top" | |- valign="top" | ||
| Status | | Status | ||
Line 37: | Line 36: | ||
| not null | | not null | ||
| ((1)) | | ((1)) | ||
− | | Order current status. 1 = Pending; 2 = Approved; 3 = Rejected; 4 = Complete | + | | Order current status. 1 = Pending; 2 = Approved; 3 = Rejected; 4 = Complete |
|- valign="top" | |- valign="top" | ||
| EmployeeID | | EmployeeID | ||
Line 43: | Line 42: | ||
| not null | | not null | ||
| | | | ||
− | | Employee who created the purchase order. Foreign key to Employee.EmployeeID. | + | | Employee who created the purchase order. Foreign key to Employee.EmployeeID. |
|- valign="top" | |- valign="top" | ||
| VendorID | | VendorID | ||
Line 49: | Line 48: | ||
| not null | | not null | ||
| | | | ||
− | | Vendor with whom the purchase order is placed. Foreign key to Vendor.VendorID. | + | | Vendor with whom the purchase order is placed. Foreign key to Vendor.VendorID. |
|- valign="top" | |- valign="top" | ||
| ShipMethodID | | ShipMethodID | ||
Line 55: | Line 54: | ||
| not null | | not null | ||
| | | | ||
− | | Shipping method. Foreign key to ShipMethod.ShipMethodID. | + | | Shipping method. Foreign key to ShipMethod.ShipMethodID. |
|- valign="top" | |- valign="top" | ||
| OrderDate | | OrderDate | ||
Line 61: | Line 60: | ||
| not null | | not null | ||
| (getdate()) | | (getdate()) | ||
− | | Purchase order creation date. | + | | Purchase order creation date. |
|- valign="top" | |- valign="top" | ||
| ShipDate | | ShipDate | ||
Line 67: | Line 66: | ||
| null | | null | ||
| | | | ||
− | | Estimated shipment date from the vendor. | + | | Estimated shipment date from the vendor. |
|- valign="top" | |- valign="top" | ||
| SubTotal | | SubTotal | ||
Line 73: | Line 72: | ||
| not null | | not null | ||
| ((0.00)) | | ((0.00)) | ||
− | | Purchase order subtotal. Computed as SUM(PurchaseOrderDetail.LineTotal)for the appropriate PurchaseOrderID. | + | | Purchase order subtotal. Computed as SUM(PurchaseOrderDetail.LineTotal)for the appropriate PurchaseOrderID. |
|- valign="top" | |- valign="top" | ||
| TaxAmt | | TaxAmt | ||
Line 79: | Line 78: | ||
| not null | | not null | ||
| ((0.00)) | | ((0.00)) | ||
− | | Tax amount. | + | | Tax amount. |
|- valign="top" | |- valign="top" | ||
| Freight | | Freight | ||
Line 85: | Line 84: | ||
| not null | | not null | ||
| ((0.00)) | | ((0.00)) | ||
− | | Shipping cost. | + | | Shipping cost. |
|- valign="top" | |- valign="top" | ||
| TotalDue | | TotalDue | ||
Line 91: | Line 90: | ||
| | | | ||
| | | | ||
− | | Total due to vendor. Computed as Subtotal + TaxAmt + Freight. | + | | Total due to vendor. Computed as Subtotal + TaxAmt + Freight. |
|- valign="top" | |- valign="top" | ||
| ModifiedDate | | ModifiedDate | ||
Line 97: | Line 96: | ||
| not null | | not null | ||
| (getdate()) | | (getdate()) | ||
− | | Date and time the record was last updated. | + | | 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_PurchaseOrderHeader_PurchaseOrderID | ||
+ | | PurchaseOrderID | ||
+ | |} | ||
+ | === Indexes === | ||
+ | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
+ | |- style="background:silver" | ||
+ | | '''Index | ||
+ | | '''Type | ||
+ | | '''Columns | ||
+ | |||
+ | |- valign="top" | ||
+ | | IX_PurchaseOrderHeader_EmployeeID | ||
+ | | | ||
+ | | EmployeeID | ||
+ | |- valign="top" | ||
+ | | IX_PurchaseOrderHeader_VendorID | ||
+ | | | ||
+ | | VendorID | ||
+ | |} | ||
+ | === Check Constraints === | ||
+ | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
+ | |- style="background:silver" | ||
+ | | '''Check Constraint | ||
+ | | '''Expression | ||
+ | | '''Description | ||
+ | |||
+ | |- valign="top" | ||
+ | | CK_PurchaseOrderHeader_Freight | ||
+ | | ([Freight]>=(0.00)) | ||
+ | | Check constraint [Freight] >= (0.00) | ||
+ | |- valign="top" | ||
+ | | CK_PurchaseOrderHeader_ShipDate | ||
+ | | ([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL) | ||
+ | | Check constraint [ShipDate] >= [OrderDate] OR [ShipDate] IS NULL | ||
+ | |- valign="top" | ||
+ | | CK_PurchaseOrderHeader_Status | ||
+ | | ([Status]>=(1) AND [Status]<=(4)) | ||
+ | | Check constraint [Status] BETWEEN (1) AND (4) | ||
+ | |- valign="top" | ||
+ | | CK_PurchaseOrderHeader_SubTotal | ||
+ | | ([SubTotal]>=(0.00)) | ||
+ | | Check constraint [SubTotal] >= (0.00) | ||
+ | |- valign="top" | ||
+ | | CK_PurchaseOrderHeader_TaxAmt | ||
+ | | ([TaxAmt]>=(0.00)) | ||
+ | | Check constraint [TaxAmt] >= (0.00) | ||
+ | |} | ||
+ | |||
+ | === 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 107: | Line 161: | ||
| '''Column | | '''Column | ||
| '''Referenced Column | | '''Referenced Column | ||
− | + | ||
− | |- | + | |- valign="top" |
| [[HumanResources.Employee_(table)|HumanResources.Employee]] | | [[HumanResources.Employee_(table)|HumanResources.Employee]] | ||
| EmployeeID | | EmployeeID | ||
| EmployeeID | | EmployeeID | ||
− | |- | + | |- valign="top" |
| [[Purchasing.ShipMethod_(table)|Purchasing.ShipMethod]] | | [[Purchasing.ShipMethod_(table)|Purchasing.ShipMethod]] | ||
| ShipMethodID | | ShipMethodID | ||
| ShipMethodID | | ShipMethodID | ||
− | |- | + | |- valign="top" |
| [[Purchasing.Vendor_(table)|Purchasing.Vendor]] | | [[Purchasing.Vendor_(table)|Purchasing.Vendor]] | ||
| VendorID | | VendorID | ||
Line 122: | Line 176: | ||
|} | |} | ||
− | + | === 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 128: | Line 182: | ||
| '''Column | | '''Column | ||
| '''Referencing Column | | '''Referencing Column | ||
− | + | ||
− | |- | + | |- valign="top" |
| [[Purchasing.PurchaseOrderDetail_(table)|Purchasing.PurchaseOrderDetail]] | | [[Purchasing.PurchaseOrderDetail_(table)|Purchasing.PurchaseOrderDetail]] | ||
| PurchaseOrderID | | PurchaseOrderID | ||
Line 135: | Line 189: | ||
|} | |} | ||
− | + | === 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 |
| '''Type | | '''Type | ||
− | + | ||
− | |- | + | |- valign="top" |
| uPurchaseOrderHeader | | uPurchaseOrderHeader | ||
| ON UPDATE | | ON UPDATE | ||
|} | |} | ||
+ | ==== Trigger uPurchaseOrderHeader ==== | ||
+ | <pre> | ||
+ | CREATE TRIGGER [Purchasing].[uPurchaseOrderHeader] ON [Purchasing].[PurchaseOrderHeader] | ||
+ | AFTER UPDATE AS | ||
+ | BEGIN | ||
+ | DECLARE @Count int; | ||
+ | SET @Count = @@ROWCOUNT; | ||
+ | IF @Count = 0 | ||
+ | RETURN; | ||
+ | |||
+ | SET NOCOUNT ON; | ||
+ | |||
+ | BEGIN TRY | ||
+ | -- Update RevisionNumber for modification of any field EXCEPT the Status. | ||
+ | IF NOT UPDATE([Status]) | ||
+ | BEGIN | ||
+ | UPDATE [Purchasing].[PurchaseOrderHeader] | ||
+ | SET [Purchasing].[PurchaseOrderHeader].[RevisionNumber] = | ||
+ | [Purchasing].[PurchaseOrderHeader].[RevisionNumber] + 1 | ||
+ | WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] IN | ||
+ | (SELECT inserted.[PurchaseOrderID] 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" | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
|- style="background:silver" | |- style="background:silver" | ||
Line 156: | Line 249: | ||
| '''Child Object | | '''Child Object | ||
− | |- | + | |- valign="top" |
+ | | Schema | ||
+ | | Schema | ||
+ | | [[Purchasing_(schema)|Purchasing]] | ||
+ | |||
+ | | | ||
+ | | | ||
+ | |- valign="top" | ||
| Update | | Update | ||
| Table | | Table | ||
Line 163: | Line 263: | ||
| Trigger | | Trigger | ||
| uPurchaseOrderHeader | | uPurchaseOrderHeader | ||
− | |- | + | |- valign="top" |
| Execute | | Execute | ||
| Procedure | | Procedure | ||
Line 170: | Line 270: | ||
| Trigger | | Trigger | ||
| uPurchaseOrderHeader | | uPurchaseOrderHeader | ||
− | |- | + | |- valign="top" |
| Execute | | Execute | ||
| Procedure | | Procedure | ||
Line 179: | Line 279: | ||
|} | |} | ||
− | + | === Dependencies === | |
{| 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 189: | Line 289: | ||
| '''Child Object | | '''Child Object | ||
− | |- | + | |- valign="top" |
| Select | | Select | ||
| Table | | Table | ||
Line 196: | Line 296: | ||
| Trigger | | Trigger | ||
| iPurchaseOrderDetail | | iPurchaseOrderDetail | ||
− | |- | + | |- valign="top" |
| Update | | Update | ||
| Table | | Table | ||
Line 203: | Line 303: | ||
| Trigger | | Trigger | ||
| iPurchaseOrderDetail | | iPurchaseOrderDetail | ||
− | |- | + | |- valign="top" |
| Update | | Update | ||
| Table | | Table | ||
Line 210: | Line 310: | ||
| Trigger | | Trigger | ||
| uPurchaseOrderDetail | | uPurchaseOrderDetail | ||
− | |- | + | |- valign="top" |
| Update | | Update | ||
| Table | | Table | ||
Line 218: | Line 318: | ||
| uPurchaseOrderHeader | | uPurchaseOrderHeader | ||
|} | |} | ||
− | |||
Latest revision as of 09:56, 27 August 2011
Contents
wikibot[edit]
Table | Purchasing.PurchaseOrderHeader |
Description | General purchase order information. See PurchaseOrderDetail. |
Columns[edit]
Column | Data Type | Nullable | Default | Description |
PurchaseOrderID | int | not null | Primary key. | |
RevisionNumber | tinyint | not null | ((0)) | Incremental number to track changes to the purchase order over time. |
Status | tinyint | not null | ((1)) | Order current status. 1 = Pending; 2 = Approved; 3 = Rejected; 4 = Complete |
EmployeeID | int | not null | Employee who created the purchase order. Foreign key to Employee.EmployeeID. | |
VendorID | int | not null | Vendor with whom the purchase order is placed. Foreign key to Vendor.VendorID. | |
ShipMethodID | int | not null | Shipping method. Foreign key to ShipMethod.ShipMethodID. | |
OrderDate | datetime | not null | (getdate()) | Purchase order creation date. |
ShipDate | datetime | null | Estimated shipment date from the vendor. | |
SubTotal | money | not null | ((0.00)) | Purchase order subtotal. Computed as SUM(PurchaseOrderDetail.LineTotal)for the appropriate PurchaseOrderID. |
TaxAmt | money | not null | ((0.00)) | Tax amount. |
Freight | money | not null | ((0.00)) | Shipping cost. |
TotalDue | Total due to vendor. Computed as Subtotal + TaxAmt + Freight. | |||
ModifiedDate | datetime | not null | (getdate()) | Date and time the record was last updated. |
Primary Key[edit]
Primary Key | Columns |
PK_PurchaseOrderHeader_PurchaseOrderID | PurchaseOrderID |
Indexes[edit]
Index | Type | Columns |
IX_PurchaseOrderHeader_EmployeeID | EmployeeID | |
IX_PurchaseOrderHeader_VendorID | VendorID |
Check Constraints[edit]
Check Constraint | Expression | Description |
CK_PurchaseOrderHeader_Freight | ([Freight]>=(0.00)) | Check constraint [Freight] >= (0.00) |
CK_PurchaseOrderHeader_ShipDate | ([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL) | Check constraint [ShipDate] >= [OrderDate] OR [ShipDate] IS NULL |
CK_PurchaseOrderHeader_Status | ([Status]>=(1) AND [Status]<=(4)) | Check constraint [Status] BETWEEN (1) AND (4) |
CK_PurchaseOrderHeader_SubTotal | ([SubTotal]>=(0.00)) | Check constraint [SubTotal] >= (0.00) |
CK_PurchaseOrderHeader_TaxAmt | ([TaxAmt]>=(0.00)) | Check constraint [TaxAmt] >= (0.00) |
Foreign Keys[edit]
Relation | Column | Referenced Column |
HumanResources.Employee | EmployeeID | EmployeeID |
Purchasing.ShipMethod | ShipMethodID | ShipMethodID |
Purchasing.Vendor | VendorID | VendorID |
Detail Tables[edit]
Detail Table | Column | Referencing Column |
Purchasing.PurchaseOrderDetail | PurchaseOrderID | PurchaseOrderID |
Triggers[edit]
Trigger | Type |
uPurchaseOrderHeader | ON UPDATE |
Trigger uPurchaseOrderHeader[edit]
CREATE TRIGGER [Purchasing].[uPurchaseOrderHeader] ON [Purchasing].[PurchaseOrderHeader] AFTER UPDATE AS BEGIN DECLARE @Count int; SET @Count = @@ROWCOUNT; IF @Count = 0 RETURN; SET NOCOUNT ON; BEGIN TRY -- Update RevisionNumber for modification of any field EXCEPT the Status. IF NOT UPDATE([Status]) BEGIN UPDATE [Purchasing].[PurchaseOrderHeader] SET [Purchasing].[PurchaseOrderHeader].[RevisionNumber] = [Purchasing].[PurchaseOrderHeader].[RevisionNumber] + 1 WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] IN (SELECT inserted.[PurchaseOrderID] 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;
References[edit]
Dependency Type | Object Type | Referenced Object | Child Type | Child Object |
Schema | Schema | Purchasing | ||
Update | Table | Purchasing.PurchaseOrderHeader | Trigger | uPurchaseOrderHeader |
Execute | Procedure | dbo.uspLogError | Trigger | uPurchaseOrderHeader |
Execute | Procedure | dbo.uspPrintError | Trigger | uPurchaseOrderHeader |
Dependencies[edit]
Reference Type | Object Type | Referencing Object | Child Type | Child Object |
Select | Table | Purchasing.PurchaseOrderDetail | Trigger | iPurchaseOrderDetail |
Update | Table | Purchasing.PurchaseOrderDetail | Trigger | iPurchaseOrderDetail |
Update | Table | Purchasing.PurchaseOrderDetail | Trigger | uPurchaseOrderDetail |
Update | Table | Purchasing.PurchaseOrderHeader | Trigger | uPurchaseOrderHeader |
automatically generated[edit]
Table | Purchasing.PurchaseOrderHeader |
Description | General purchase order information. See PurchaseOrderDetail. |
Column | Data Type | Nullable | Default | Description / PK / Index |
PurchaseOrderID | int | not null | Primary key. PK_PurchaseOrderHeader_PurchaseOrderID | |
RevisionNumber | tinyint | not null | (0) | Incremental number to track changes to the purchase order over time. |
Status | tinyint | not null | (1) | Order current status. 1 = Pending; 2 = Approved; 3 = Rejected; 4 = Complete |
EmployeeID | int | not null | Employee who created the purchase order. Foreign key to Employee.EmployeeID. IX_PurchaseOrderHeader_EmployeeID | |
VendorID | int | not null | Vendor with whom the purchase order is placed. Foreign key to Vendor.VendorID. IX_PurchaseOrderHeader_VendorID | |
ShipMethodID | int | not null | Shipping method. Foreign key to ShipMethod.ShipMethodID. | |
OrderDate | datetime | not null | (GETDATE()) | Purchase order creation date. |
ShipDate | datetime | null | Estimated shipment date from the vendor. | |
SubTotal | money | not null | (0.00) | Purchase order subtotal. Computed as SUM(PurchaseOrderDetail.LineTotal)for the appropriate PurchaseOrderID. |
TaxAmt | money | not null | (0.00) | Tax amount. |
Freight | money | not null | (0.00) | Shipping cost. |
TotalDue | Total due to vendor. Computed as Subtotal + TaxAmt + Freight. | |||
ModifiedDate | datetime | not null | (GETDATE()) | Date and time the record was last updated. |
Relation | Column | Referenced Column |
HumanResources.Employee | EmployeeID | EmployeeID |
Purchasing.ShipMethod | ShipMethodID | ShipMethodID |
Purchasing.Vendor | VendorID | VendorID |
Detail Table | Column | Referencing Column |
Purchasing.PurchaseOrderDetail | PurchaseOrderID | PurchaseOrderID |
Triggers | Type |
uPurchaseOrderHeader | ON UPDATE |
Dependency Type | Object Type | Referenced Object | Child Type | Child Object |
Schema | Schema | Purchasing | ||
Update | Table | Purchasing.PurchaseOrderHeader | Trigger | uPurchaseOrderHeader |
Execute | Procedure | dbo.uspLogError | Trigger | uPurchaseOrderHeader |
Execute | Procedure | dbo.uspPrintError | Trigger | uPurchaseOrderHeader |
Reference Type | Object Type | Referencing Object | Child Type | Child Object |
Select | Table | Purchasing.PurchaseOrderDetail | Trigger | iPurchaseOrderDetail |
Update | Table | Purchasing.PurchaseOrderDetail | Trigger | iPurchaseOrderDetail |
Update | Table | Purchasing.PurchaseOrderDetail | Trigger | uPurchaseOrderDetail |
Update | Table | Purchasing.PurchaseOrderHeader | Trigger | uPurchaseOrderHeader |