• lsrep17 Documentation
  • Tables [Sales].[SalesOrderHeader]
    General sales order information.
    PropertyValue
    CollationSQL_Latin1_General_CP1_CI_AS
    Row Count (~)31465
    Created13:14:19 14 marca 2012
    Last Modified13:14:55 14 marca 2012
    KeyNameData TypeComputedMax Length (Bytes)Allow NullsIdentityIdentity ReplicationDefaultDescription
    Cluster Primary Key PK_SalesOrderHeader_SalesOrderID: SalesOrderIDSalesOrderIDint4
    False
    1 - 1
    False
    Primary key.
    RevisionNumbertinyint1
    False
    ((0))Incremental number to track changes to the sales order over time.
    OrderDatedatetime8
    False
    (getdate())Dates the sales order was created.
    DueDatedatetime8
    False
    Date the order is due to the customer.
    ShipDatedatetime8
    True
    Date the order was shipped to the customer.
    Check Constraints CK_SalesOrderHeader_Status : ([Status]>=(0) AND [Status]<=(8))Statustinyint1
    False
    ((1))Order current status. 1 = In process; 2 = Approved; 3 = Backordered; 4 = Rejected; 5 = Shipped; 6 = Cancelled
    OnlineOrderFlag[dbo].[Flag]1
    False
    ((1))0 = Order placed by sales person. 1 = Order placed online by customer.
    Indexes AK_SalesOrderHeader_SalesOrderNumberSalesOrderNumbernvarchar(25)
    True
    50
    False
    Unique sales order identification number.
    PurchaseOrderNumber[dbo].[OrderNumber]50
    True
    Customer purchase order number reference.
    AccountNumber[dbo].[AccountNumber]30
    True
    Financial accounting number reference.
    Indexes IX_SalesOrderHeader_CustomerIDForeign Keys FK_SalesOrderHeader_Customer_CustomerID: [Sales].[Customer].CustomerIDCustomerIDint4
    False
    Customer identification number. Foreign key to Customer.BusinessEntityID.
    Indexes IX_SalesOrderHeader_SalesPersonIDForeign Keys FK_SalesOrderHeader_SalesPerson_SalesPersonID: [Sales].[SalesPerson].SalesPersonIDSalesPersonIDint4
    True
    Sales person who created the sales order. Foreign key to SalesPerson.BusinessEntityID.
    Foreign Keys FK_SalesOrderHeader_SalesTerritory_TerritoryID: [Sales].[SalesTerritory].TerritoryIDTerritoryIDint4
    True
    Territory in which the sale was made. Foreign key to SalesTerritory.SalesTerritoryID.
    Foreign Keys FK_SalesOrderHeader_Address_BillToAddressID: [Person].[Address].BillToAddressIDBillToAddressIDint4
    False
    Customer billing address. Foreign key to Address.AddressID.
    Foreign Keys FK_SalesOrderHeader_Address_ShipToAddressID: [Person].[Address].ShipToAddressIDShipToAddressIDint4
    False
    Customer shipping address. Foreign key to Address.AddressID.
    Foreign Keys FK_SalesOrderHeader_ShipMethod_ShipMethodID: [Purchasing].[ShipMethod].ShipMethodIDShipMethodIDint4
    False
    Shipping method. Foreign key to ShipMethod.ShipMethodID.
    Foreign Keys FK_SalesOrderHeader_CreditCard_CreditCardID: [Sales].[CreditCard].CreditCardIDCreditCardIDint4
    True
    Credit card identification number. Foreign key to CreditCard.CreditCardID.
    CreditCardApprovalCodevarchar(15)15
    True
    Approval code provided by the credit card company.
    Foreign Keys FK_SalesOrderHeader_CurrencyRate_CurrencyRateID: [Sales].[CurrencyRate].CurrencyRateIDCurrencyRateIDint4
    True
    Currency exchange rate used. Foreign key to CurrencyRate.CurrencyRateID.
    Check Constraints CK_SalesOrderHeader_SubTotal : ([SubTotal]>=(0.00))SubTotalmoney8
    False
    ((0.00))Sales subtotal. Computed as SUM(SalesOrderDetail.LineTotal)for the appropriate SalesOrderID.
    Check Constraints CK_SalesOrderHeader_TaxAmt : ([TaxAmt]>=(0.00))TaxAmtmoney8
    False
    ((0.00))Tax amount.
    Check Constraints CK_SalesOrderHeader_Freight : ([Freight]>=(0.00))Freightmoney8
    False
    ((0.00))Shipping cost.
    TotalDuemoney
    True
    8
    False
    Total due from customer. Computed as Subtotal + TaxAmt + Freight.
    Commentnvarchar(128)256
    True
    Sales representative comments.
    Indexes AK_SalesOrderHeader_rowguidrowguiduniqueidentifier16
    False
    (newid())ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
    ModifiedDatedatetime8
    False
    (getdate())Date and time the record was last updated.
    NameColumn definition
    SalesOrderNumber(isnull(N'SO'+CONVERT([nvarchar](23),[SalesOrderID],(0)),N'*** ERROR ***'))
    TotalDue(isnull(([SubTotal]+[TaxAmt])+[Freight],(0)))
    KeyNameKey ColumnsUniqueDescription
    Cluster Primary Key PK_SalesOrderHeader_SalesOrderID: SalesOrderIDPK_SalesOrderHeader_SalesOrderIDSalesOrderID
    True
    Primary key (clustered) constraint
    AK_SalesOrderHeader_SalesOrderNumberSalesOrderNumber
    True
    Unique nonclustered index.
    AK_SalesOrderHeader_rowguidrowguid
    True
    Unique nonclustered index. Used to support replication samples.
    IX_SalesOrderHeader_CustomerIDCustomerIDNonclustered index.
    IX_SalesOrderHeader_SalesPersonIDSalesPersonIDNonclustered index.
    NameANSI Nulls OnQuoted Identifier OnOnNot For ReplicationDescription
    uSalesOrderHeader
    True
    True
    After Update
    True
    AFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the SalesOrderHeader table.Updates the SalesYTD column in the SalesPerson and SalesTerritory tables.
    NameOn ColumnConstraintDescription
    CK_SalesOrderHeader_DueDate([DueDate]>=[OrderDate])Check constraint [DueDate] >= [OrderDate]
    CK_SalesOrderHeader_FreightFreight([Freight]>=(0.00))Check constraint [Freight] >= (0.00)
    CK_SalesOrderHeader_ShipDate([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL)Check constraint [ShipDate] >= [OrderDate] OR [ShipDate] IS NULL
    CK_SalesOrderHeader_StatusStatus([Status]>=(0) AND [Status]<=(8))Check constraint [Status] BETWEEN (0) AND (8)
    CK_SalesOrderHeader_SubTotalSubTotal([SubTotal]>=(0.00))Check constraint [SubTotal] >= (0.00)
    CK_SalesOrderHeader_TaxAmtTaxAmt([TaxAmt]>=(0.00))Check constraint [TaxAmt] >= (0.00)
    NameColumnsDescription
    FK_SalesOrderHeader_Address_BillToAddressIDBillToAddressID->[Person].[Address].[AddressID]Foreign key constraint referencing Address.AddressID.
    FK_SalesOrderHeader_Address_ShipToAddressIDShipToAddressID->[Person].[Address].[AddressID]Foreign key constraint referencing Address.AddressID.
    FK_SalesOrderHeader_CreditCard_CreditCardIDCreditCardID->[Sales].[CreditCard].[CreditCardID]Foreign key constraint referencing CreditCard.CreditCardID.
    FK_SalesOrderHeader_CurrencyRate_CurrencyRateIDCurrencyRateID->[Sales].[CurrencyRate].[CurrencyRateID]Foreign key constraint referencing CurrencyRate.CurrencyRateID.
    FK_SalesOrderHeader_Customer_CustomerIDCustomerID->[Sales].[Customer].[CustomerID]Foreign key constraint referencing Customer.CustomerID.
    FK_SalesOrderHeader_SalesPerson_SalesPersonIDSalesPersonID->[Sales].[SalesPerson].[BusinessEntityID]Foreign key constraint referencing SalesPerson.SalesPersonID.
    FK_SalesOrderHeader_SalesTerritory_TerritoryIDTerritoryID->[Sales].[SalesTerritory].[TerritoryID]Foreign key constraint referencing SalesTerritory.TerritoryID.
    FK_SalesOrderHeader_ShipMethod_ShipMethodIDShipMethodID->[Purchasing].[ShipMethod].[ShipMethodID]Foreign key constraint referencing ShipMethod.ShipMethodID.
    CREATE TABLE [Sales].[SalesOrderHeader]
    (
    [SalesOrderID] [int] NOT NULL IDENTITY(1, 1) NOT FOR REPLICATION,
    [RevisionNumber] [tinyint] NOT NULL CONSTRAINT [DF_SalesOrderHeader_RevisionNumber] DEFAULT ((0)),
    [OrderDate] [datetime] NOT NULL CONSTRAINT [DF_SalesOrderHeader_OrderDate] DEFAULT (getdate()),
    [DueDate] [datetime] NOT NULL,
    [ShipDate] [datetime] NULL,
    [Status] [tinyint] NOT NULL CONSTRAINT [DF_SalesOrderHeader_Status] DEFAULT ((1)),
    [OnlineOrderFlag] [dbo].[Flag] NOT NULL CONSTRAINT [DF_SalesOrderHeader_OnlineOrderFlag] DEFAULT ((1)),
    [SalesOrderNumber] AS (isnull(N'SO'+CONVERT([nvarchar](23),[SalesOrderID],(0)),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 CONSTRAINT [DF_SalesOrderHeader_SubTotal] DEFAULT ((0.00)),
    [TaxAmt] [money] NOT NULL CONSTRAINT [DF_SalesOrderHeader_TaxAmt] DEFAULT ((0.00)),
    [Freight] [money] NOT NULL CONSTRAINT [DF_SalesOrderHeader_Freight] DEFAULT ((0.00)),
    [TotalDue] AS (isnull(([SubTotal]+[TaxAmt])+[Freight],(0))),
    [Comment] [nvarchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [rowguid] [uniqueidentifier] NOT NULL ROWGUIDCOL CONSTRAINT [DF_SalesOrderHeader_rowguid] DEFAULT (newid()),
    [ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_SalesOrderHeader_ModifiedDate] DEFAULT (getdate())
    ) ON [PRIMARY]
    GO

    CREATE TRIGGER [Sales].[uSalesOrderHeader] ON [Sales].[SalesOrderHeader]
    AFTER UPDATE NOT FOR REPLICATION 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 [Sales].[SalesOrderHeader]
               SET [Sales].[SalesOrderHeader].[RevisionNumber] =
                   [Sales].[SalesOrderHeader].[RevisionNumber] + 1
               WHERE [Sales].[SalesOrderHeader].[SalesOrderID] IN
                   (SELECT inserted.[SalesOrderID] FROM inserted);
           END;

           -- Update the SalesPerson SalesYTD when SubTotal is updated
           IF UPDATE([SubTotal])
           BEGIN
               DECLARE @StartDate datetime,
                       @EndDate datetime

               SET @StartDate = [dbo].[ufnGetAccountingStartDate]();
               SET @EndDate = [dbo].[ufnGetAccountingEndDate]();

               UPDATE [Sales].[SalesPerson]
               SET [Sales].[SalesPerson].[SalesYTD] =
                   (SELECT SUM([Sales].[SalesOrderHeader].[SubTotal])
                   FROM [Sales].[SalesOrderHeader]
                   WHERE [Sales].[SalesPerson].[BusinessEntityID] = [Sales].[SalesOrderHeader].[SalesPersonID]
                       AND ([Sales].[SalesOrderHeader].[Status] = 5) -- Shipped
                       AND [Sales].[SalesOrderHeader].[OrderDate] BETWEEN @StartDate AND @EndDate)
               WHERE [Sales].[SalesPerson].[BusinessEntityID]
                   IN (SELECT DISTINCT inserted.[SalesPersonID] FROM inserted
                       WHERE inserted.[OrderDate] BETWEEN @StartDate AND @EndDate);

               -- Update the SalesTerritory SalesYTD when SubTotal is updated
               UPDATE [Sales].[SalesTerritory]
               SET [Sales].[SalesTerritory].[SalesYTD] =
                   (SELECT SUM([Sales].[SalesOrderHeader].[SubTotal])
                   FROM [Sales].[SalesOrderHeader]
                   WHERE [Sales].[SalesTerritory].[TerritoryID] = [Sales].[SalesOrderHeader].[TerritoryID]
                       AND ([Sales].[SalesOrderHeader].[Status] = 5) -- Shipped
                       AND [Sales].[SalesOrderHeader].[OrderDate] BETWEEN @StartDate AND @EndDate)
               WHERE [Sales].[SalesTerritory].[TerritoryID]
                   IN (SELECT DISTINCT inserted.[TerritoryID] FROM inserted
                       WHERE inserted.[OrderDate] BETWEEN @StartDate AND @EndDate);
           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;
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [CK_SalesOrderHeader_DueDate] CHECK (([DueDate]>=[OrderDate]))
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [CK_SalesOrderHeader_Freight] CHECK (([Freight]>=(0.00)))
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [CK_SalesOrderHeader_ShipDate] CHECK (([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL))
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [CK_SalesOrderHeader_Status] CHECK (([Status]>=(0) AND [Status]<=(8)))
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [CK_SalesOrderHeader_SubTotal] CHECK (([SubTotal]>=(0.00)))
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [CK_SalesOrderHeader_TaxAmt] CHECK (([TaxAmt]>=(0.00)))
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [PK_SalesOrderHeader_SalesOrderID] PRIMARY KEY CLUSTERED  ([SalesOrderID]) ON [PRIMARY]
    GO
    CREATE NONCLUSTERED INDEX [IX_SalesOrderHeader_CustomerID] ON [Sales].[SalesOrderHeader] ([CustomerID]) ON [PRIMARY]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesOrderHeader_rowguid] ON [Sales].[SalesOrderHeader] ([rowguid]) ON [PRIMARY]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesOrderHeader_SalesOrderNumber] ON [Sales].[SalesOrderHeader] ([SalesOrderNumber]) ON [PRIMARY]
    GO
    CREATE NONCLUSTERED INDEX [IX_SalesOrderHeader_SalesPersonID] ON [Sales].[SalesOrderHeader] ([SalesPersonID]) ON [PRIMARY]
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID] FOREIGN KEY ([BillToAddressID]) REFERENCES [Person].[Address] ([AddressID])
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [FK_SalesOrderHeader_Address_ShipToAddressID] FOREIGN KEY ([ShipToAddressID]) REFERENCES [Person].[Address] ([AddressID])
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [FK_SalesOrderHeader_CreditCard_CreditCardID] FOREIGN KEY ([CreditCardID]) REFERENCES [Sales].[CreditCard] ([CreditCardID])
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [FK_SalesOrderHeader_CurrencyRate_CurrencyRateID] FOREIGN KEY ([CurrencyRateID]) REFERENCES [Sales].[CurrencyRate] ([CurrencyRateID])
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [FK_SalesOrderHeader_Customer_CustomerID] FOREIGN KEY ([CustomerID]) REFERENCES [Sales].[Customer] ([CustomerID])
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] FOREIGN KEY ([SalesPersonID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID])
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID])
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] ADD CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY ([ShipMethodID]) REFERENCES [Purchasing].[ShipMethod] ([ShipMethodID])
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'General sales order information.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', NULL, NULL
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Financial accounting number reference.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'AccountNumber'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Customer billing address. Foreign key to Address.AddressID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'BillToAddressID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Sales representative comments.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'Comment'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Approval code provided by the credit card company.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'CreditCardApprovalCode'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Credit card identification number. Foreign key to CreditCard.CreditCardID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'CreditCardID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Currency exchange rate used. Foreign key to CurrencyRate.CurrencyRateID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'CurrencyRateID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Customer identification number. Foreign key to Customer.BusinessEntityID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'CustomerID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Date the order is due to the customer.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'DueDate'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Shipping cost.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'Freight'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Date and time the record was last updated.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'ModifiedDate'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'0 = Order placed by sales person. 1 = Order placed online by customer.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'OnlineOrderFlag'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Dates the sales order was created.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'OrderDate'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Customer purchase order number reference. ', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'PurchaseOrderNumber'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Incremental number to track changes to the sales order over time.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'RevisionNumber'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'rowguid'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Primary key.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'SalesOrderID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Unique sales order identification number.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'SalesOrderNumber'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Sales person who created the sales order. Foreign key to SalesPerson.BusinessEntityID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'SalesPersonID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Date the order was shipped to the customer.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'ShipDate'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Shipping method. Foreign key to ShipMethod.ShipMethodID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'ShipMethodID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Customer shipping address. Foreign key to Address.AddressID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'ShipToAddressID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Order current status. 1 = In process; 2 = Approved; 3 = Backordered; 4 = Rejected; 5 = Shipped; 6 = Cancelled', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'Status'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Sales subtotal. Computed as SUM(SalesOrderDetail.LineTotal)for the appropriate SalesOrderID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'SubTotal'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Tax amount.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'TaxAmt'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Territory in which the sale was made. Foreign key to SalesTerritory.SalesTerritoryID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'TerritoryID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Total due from customer. Computed as Subtotal + TaxAmt + Freight.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'COLUMN', N'TotalDue'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Check constraint [DueDate] >= [OrderDate]', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'CK_SalesOrderHeader_DueDate'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Check constraint [Freight] >= (0.00)', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'CK_SalesOrderHeader_Freight'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Check constraint [ShipDate] >= [OrderDate] OR [ShipDate] IS NULL', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'CK_SalesOrderHeader_ShipDate'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Check constraint [Status] BETWEEN (0) AND (8)', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'CK_SalesOrderHeader_Status'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Check constraint [SubTotal] >= (0.00)', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'CK_SalesOrderHeader_SubTotal'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Check constraint [TaxAmt] >= (0.00)', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'CK_SalesOrderHeader_TaxAmt'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of 0.0', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_Freight'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of GETDATE()', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_ModifiedDate'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of 1 (TRUE)', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_OnlineOrderFlag'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of GETDATE()', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_OrderDate'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of 0', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_RevisionNumber'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of NEWID()', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_rowguid'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of 1', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_Status'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of 0.0', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_SubTotal'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Default constraint value of 0.0', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'DF_SalesOrderHeader_TaxAmt'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Foreign key constraint referencing Address.AddressID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'FK_SalesOrderHeader_Address_BillToAddressID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Foreign key constraint referencing Address.AddressID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'FK_SalesOrderHeader_Address_ShipToAddressID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Foreign key constraint referencing CreditCard.CreditCardID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'FK_SalesOrderHeader_CreditCard_CreditCardID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Foreign key constraint referencing CurrencyRate.CurrencyRateID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'FK_SalesOrderHeader_CurrencyRate_CurrencyRateID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Foreign key constraint referencing Customer.CustomerID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'FK_SalesOrderHeader_Customer_CustomerID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Foreign key constraint referencing SalesPerson.SalesPersonID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'FK_SalesOrderHeader_SalesPerson_SalesPersonID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Foreign key constraint referencing SalesTerritory.TerritoryID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'FK_SalesOrderHeader_SalesTerritory_TerritoryID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Foreign key constraint referencing ShipMethod.ShipMethodID.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'FK_SalesOrderHeader_ShipMethod_ShipMethodID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Primary key (clustered) constraint', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'CONSTRAINT', N'PK_SalesOrderHeader_SalesOrderID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Unique nonclustered index. Used to support replication samples.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'INDEX', N'AK_SalesOrderHeader_rowguid'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Unique nonclustered index.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'INDEX', N'AK_SalesOrderHeader_SalesOrderNumber'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Nonclustered index.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'INDEX', N'IX_SalesOrderHeader_CustomerID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Nonclustered index.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'INDEX', N'IX_SalesOrderHeader_SalesPersonID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'Clustered index created by a primary key constraint.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'INDEX', N'PK_SalesOrderHeader_SalesOrderID'
    GO
    EXEC sp_addextendedproperty N'MS_Description', N'AFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the SalesOrderHeader table.Updates the SalesYTD column in the SalesPerson and SalesTerritory tables.', 'SCHEMA', N'Sales', 'TABLE', N'SalesOrderHeader', 'TRIGGER', N'uSalesOrderHeader'
    GO