Source code SQL 2005 Adventure Works OLTP

Sales.SalesOrderHeader




CREATE TABLE [Sales].[SalesOrderHeader](
    [SalesOrderID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL,
    [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] [Flag] NOT NULL CONSTRAINT [DF_SalesOrderHeader_OnlineOrderFlag] DEFAULT (1),
    [SalesOrderNumber] AS ISNULL(N'SO' + CONVERT(nvarchar(23), [SalesOrderID]), N'*** ERROR ***'),
    [PurchaseOrderNumber] [OrderNumber] NULL,
    [AccountNumber] [AccountNumber] NULL,
    [CustomerID] [int] NOT NULL,
    [ContactID] [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) 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) NULL,
    [rowguid] uniqueidentifier ROWGUIDCOL NOT NULL CONSTRAINT [DF_SalesOrderHeader_rowguid] DEFAULT (NEWID()),
    [ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_SalesOrderHeader_ModifiedDate] DEFAULT (GETDATE()),
    CONSTRAINT [CK_SalesOrderHeader_Status] CHECK ([Status] BETWEEN 0 AND 8),
    CONSTRAINT [CK_SalesOrderHeader_DueDate] CHECK ([DueDate] >= [OrderDate]),
    CONSTRAINT [CK_SalesOrderHeader_ShipDate] CHECK (([ShipDate] >= [OrderDate]) OR ([ShipDate] IS NULL)),
    CONSTRAINT [CK_SalesOrderHeader_SubTotal] CHECK ([SubTotal] >= 0.00),
    CONSTRAINT [CK_SalesOrderHeader_TaxAmt] CHECK ([TaxAmt] >= 0.00),
    CONSTRAINT [CK_SalesOrderHeader_Freight] CHECK ([Freight] >= 0.00)
) ON [PRIMARY];




ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD
    CONSTRAINT [PK_SalesOrderHeader_SalesOrderID] PRIMARY KEY CLUSTERED
    (
        [SalesOrderID]
    )  ON [PRIMARY];




ALTER TABLE [Sales].[SalesOrderHeader] ADD
    CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID] FOREIGN KEY
    (
        [BillToAddressID]
    ) REFERENCES [Person].[Address](
        [AddressID]
    ),
    CONSTRAINT [FK_SalesOrderHeader_Address_ShipToAddressID] FOREIGN KEY
    (
        [ShipToAddressID]
    ) REFERENCES [Person].[Address](
        [AddressID]
    ),
    CONSTRAINT [FK_SalesOrderHeader_Contact_ContactID] FOREIGN KEY
    (
        [ContactID]
    ) REFERENCES [Person].[Contact](
        [ContactID]
    ),
    CONSTRAINT [FK_SalesOrderHeader_CreditCard_CreditCardID] FOREIGN KEY
    (
        [CreditCardID]
    ) REFERENCES [Sales].[CreditCard](
        [CreditCardID]
    ),
    CONSTRAINT [FK_SalesOrderHeader_CurrencyRate_CurrencyRateID] FOREIGN KEY
    (
        [CurrencyRateID]
    ) REFERENCES [Sales].[CurrencyRate](
        [CurrencyRateID]
    ),
    CONSTRAINT [FK_SalesOrderHeader_Customer_CustomerID] FOREIGN KEY
    (
        [CustomerID]
    ) REFERENCES [Sales].[Customer](
        [CustomerID]
    ),
    CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] FOREIGN KEY
    (
        [SalesPersonID]
    ) REFERENCES [Sales].[SalesPerson](
        [SalesPersonID]
    ),
    CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY
    (
        [ShipMethodID]
    ) REFERENCES [Purchasing].[ShipMethod](
        [ShipMethodID]
    ),
    CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] FOREIGN KEY
    (
        [TerritoryID]
    ) REFERENCES [Sales].[SalesTerritory](
        [TerritoryID]
    );





EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'General sales order information.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], NULL, NULL;
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Primary key.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [SalesOrderID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Incremental number to track changes to the sales order over time.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [RevisionNumber];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Dates the sales order was created.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [OrderDate];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Date the order is due to the customer.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [DueDate];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Date the order was shipped to the customer.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [ShipDate];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Order current status. 1 = In process; 2 = Approved; 3 = Backordered; 4 = Rejected; 5 = Shipped; 6 = Cancelled', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [Status];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'0 = Order placed by sales person. 1 = Order placed online by customer.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [OnlineOrderFlag];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Unique sales order identification number.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [SalesOrderNumber];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Customer purchase order number reference. ', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [PurchaseOrderNumber];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Financial accounting number reference.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [AccountNumber];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Customer identification number. Foreign key to Customer.CustomerID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [CustomerID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Customer contact identification number. Foreign key to Contact.ContactID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [ContactID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Sales person who created the sales order. Foreign key to SalesPerson.SalePersonID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [SalesPersonID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Territory in which the sale was made. Foreign key to SalesTerritory.SalesTerritoryID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [TerritoryID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Customer billing address. Foreign key to Address.AddressID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [BillToAddressID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Customer shipping address. Foreign key to Address.AddressID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [ShipToAddressID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Shipping method. Foreign key to ShipMethod.ShipMethodID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [ShipMethodID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Credit card identification number. Foreign key to CreditCard.CreditCardID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [CreditCardID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Approval code provided by the credit card company.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [CreditCardApprovalCode];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Currency exchange rate used. Foreign key to CurrencyRate.CurrencyRateID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [CurrencyRateID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Sales subtotal. Computed as SUM(SalesOrderDetail.LineTotal)for the appropriate SalesOrderID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [SubTotal];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Tax amount.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [TaxAmt];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Shipping cost.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [Freight];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Total due from customer. Computed as Subtotal + TaxAmt + Freight.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [TotalDue];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Sales representative comments.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [Comment];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [rowguid];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Date and time the record was last updated.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'COLUMN', [ModifiedDate];



-- Triggers
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Address table to the current date.', N'SCHEMA', [Person], N'TABLE', [Address], N'TRIGGER', [uAddress];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the AddressType table to the current date.', N'SCHEMA', [Person], N'TABLE', [AddressType], N'TRIGGER', [uAddressType];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the AWBuildVersion table to the current date.', N'SCHEMA', [dbo], N'TABLE', [AWBuildVersion], N'TRIGGER', [uAWBuildVersion];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the BillOfMaterials table to the current date.', N'SCHEMA', [Production], N'TABLE', [BillOfMaterials], N'TRIGGER', [uBillOfMaterials];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Contact table to the current date.', N'SCHEMA', [Person], N'TABLE', [Contact], N'TRIGGER', [uContact];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ContactCreditCard table to the current date.', N'SCHEMA', [Sales], N'TABLE', [ContactCreditCard], N'TRIGGER', [uContactCreditCard];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ContactType table to the current date.', N'SCHEMA', [Person], N'TABLE', [ContactType], N'TRIGGER', [uContactType];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the CountryRegionCurrency table to the current date.', N'SCHEMA', [Sales], N'TABLE', [CountryRegionCurrency], N'TRIGGER', [uCountryRegionCurrency];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the CountryRegion table to the current date.', N'SCHEMA', [Person], N'TABLE', [CountryRegion], N'TRIGGER', [uCountryRegion];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the CreditCard table to the current date.', N'SCHEMA', [Sales], N'TABLE', [CreditCard], N'TRIGGER', [uCreditCard];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Culture table to the current date.', N'SCHEMA', [Production], N'TABLE', [Culture], N'TRIGGER', [uCulture];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Currency table to the current date.', N'SCHEMA', [Sales], N'TABLE', [Currency], N'TRIGGER', [uCurrency];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the CurrencyRate table to the current date.', N'SCHEMA', [Sales], N'TABLE', [CurrencyRate], N'TRIGGER', [uCurrencyRate];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Customer table to the current date.', N'SCHEMA', [Sales], N'TABLE', [Customer], N'TRIGGER', [uCustomer];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the CustomerAddress table to the current date.', N'SCHEMA', [Sales], N'TABLE', [CustomerAddress], N'TRIGGER', [uCustomerAddress];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Department table to the current date.', N'SCHEMA', [HumanResources], N'TABLE', [Department], N'TRIGGER', [uDepartment];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Document table to the current date.', N'SCHEMA', [Production], N'TABLE', [Document], N'TRIGGER', [uDocument];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'INSTEAD OF DELETE trigger which keeps Employees from being deleted.', N'SCHEMA', [HumanResources], N'TABLE', [Employee], N'TRIGGER', [dEmployee];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Employee table to the current date.', N'SCHEMA', [HumanResources], N'TABLE', [Employee], N'TRIGGER', [uEmployee];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the EmployeeAddress table to the current date.', N'SCHEMA', [HumanResources], N'TABLE', [EmployeeAddress], N'TRIGGER', [uEmployeeAddress];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the EmployeeDepartmentHistory table to the current date.', N'SCHEMA', [HumanResources], N'TABLE', [EmployeeDepartmentHistory], N'TRIGGER', [uEmployeeDepartmentHistory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the EmployeePayHistory table to the current date.', N'SCHEMA', [HumanResources], N'TABLE', [EmployeePayHistory], N'TRIGGER', [uEmployeePayHistory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Illustration table to the current date.', N'SCHEMA', [Production], N'TABLE', [Illustration], N'TRIGGER', [uIllustration];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER INSERT, UPDATE trigger inserting Individual only if the Customer does not exist in the Store table and setting the ModifiedDate column in the Individual table to the current date.', N'SCHEMA', [Sales], N'TABLE', [Individual], N'TRIGGER', [iuIndividual];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the JobCandidat table to the current date.', N'SCHEMA', [HumanResources], N'TABLE', [JobCandidate], N'TRIGGER', [uJobCandidate];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Location table to the current date.', N'SCHEMA', [Production], N'TABLE', [Location], N'TRIGGER', [uLocation];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Product table to the current date.', N'SCHEMA', [Production], N'TABLE', [Product], N'TRIGGER', [uProduct];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductCategory table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductCategory], N'TRIGGER', [uProductCategory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductCostHistory table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductCostHistory], N'TRIGGER', [uProductCostHistory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductDescription table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductDescription], N'TRIGGER', [uProductDescription];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductDocument table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductDocument], N'TRIGGER', [uProductDocument];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductInventory table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductInventory], N'TRIGGER', [uProductInventory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductListPriceHistory table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductListPriceHistory], N'TRIGGER', [uProductListPriceHistory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductModel table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductModel], N'TRIGGER', [uProductModel];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductModelIllustration table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductModelIllustration], N'TRIGGER', [uProductModelIllustration];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductModelProductDescriptionCulture table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductModelProductDescriptionCulture], N'TRIGGER', [uProductModelProductDescriptionCulture];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductPhoto table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductPhoto], N'TRIGGER', [uProductPhoto];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductProductPhoto table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductProductPhoto], N'TRIGGER', [uProductProductPhoto];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductReview table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductReview], N'TRIGGER', [uProductReview];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductSubcategory table to the current date.', N'SCHEMA', [Production], N'TABLE', [ProductSubcategory], N'TRIGGER', [uProductSubcategory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ProductVendor table to the current date.', N'SCHEMA', [Purchasing], N'TABLE', [ProductVendor], N'TRIGGER', [uProductVendor];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER INSERT trigger that inserts a row in the TransactionHistory table and updates the PurchaseOrderHeader.SubTotal column.', N'SCHEMA', [Purchasing], N'TABLE', [PurchaseOrderDetail], N'TRIGGER', [iPurchaseOrderDetail];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in PurchaseOrderDetail and updates the PurchaseOrderHeader.SubTotal column.', N'SCHEMA', [Purchasing], N'TABLE', [PurchaseOrderDetail], N'TRIGGER', [uPurchaseOrderDetail];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the PurchaseOrderHeader table.', N'SCHEMA', [Purchasing], N'TABLE', [PurchaseOrderHeader], N'TRIGGER', [uPurchaseOrderHeader];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER INSERT, DELETE, UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in SalesOrderDetail and updates the SalesOrderHeader.SubTotal column.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderDetail], N'TRIGGER', [iduSalesOrderDetail];
EXEC [sys].[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.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'TRIGGER', [uSalesOrderHeader];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SalesOrderHeaderSalesReason table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeaderSalesReason], N'TRIGGER', [uSalesOrderHeaderSalesReason];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SalesPerson table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SalesPerson], N'TRIGGER', [uSalesPerson];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SalesPersonQuotaHistory table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SalesPersonQuotaHistory], N'TRIGGER', [uSalesPersonQuotaHistory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SalesReason table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SalesReason], N'TRIGGER', [uSalesReason];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SalesTaxRate table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SalesTaxRate], N'TRIGGER', [uSalesTaxRate];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SalesTerritory table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SalesTerritory], N'TRIGGER', [uSalesTerritory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SalesTerritoryHistory table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SalesTerritoryHistory], N'TRIGGER', [uSalesTerritoryHistory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ScrapReason table to the current date.', N'SCHEMA', [Production], N'TABLE', [ScrapReason], N'TRIGGER', [uScrapReason];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Shift table to the current date.', N'SCHEMA', [HumanResources], N'TABLE', [Shift], N'TRIGGER', [uShift];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ShipMethod table to the current date.', N'SCHEMA', [Purchasing], N'TABLE', [ShipMethod], N'TRIGGER', [uShipMethod];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the ShoppingCartItem table to the current date.', N'SCHEMA', [Sales], N'TABLE', [ShoppingCartItem], N'TRIGGER', [uShoppingCartItem];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SpecialOffer table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SpecialOffer], N'TRIGGER', [uSpecialOffer];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the SpecialOfferProduct table to the current date.', N'SCHEMA', [Sales], N'TABLE', [SpecialOfferProduct], N'TRIGGER', [uSpecialOfferProduct];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the StateProvince table to the current date.', N'SCHEMA', [Person], N'TABLE', [StateProvince], N'TRIGGER', [uStateProvince];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER INSERT trigger inserting Store only if the Customer does not exist in the Individual table.', N'SCHEMA', [Sales], N'TABLE', [Store], N'TRIGGER', [iStore];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Store table to the current date.', N'SCHEMA', [Sales], N'TABLE', [Store], N'TRIGGER', [uStore];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the StoreContact table to the current date.', N'SCHEMA', [Sales], N'TABLE', [StoreContact], N'TRIGGER', [uStoreContact];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the TransactionHistory table to the current date.', N'SCHEMA', [Production], N'TABLE', [TransactionHistory], N'TRIGGER', [uTransactionHistory];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the TransactionHistoryArchive table to the current date.', N'SCHEMA', [Production], N'TABLE', [TransactionHistoryArchive], N'TRIGGER', [uTransactionHistoryArchive];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the UnitMeasure table to the current date.', N'SCHEMA', [Production], N'TABLE', [UnitMeasure], N'TRIGGER', [uUnitMeasure];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'INSTEAD OF DELETE trigger which keeps Vendors from being deleted.', N'SCHEMA', [Purchasing], N'TABLE', [Vendor], N'TRIGGER', [dVendor];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the Vendor table to the current date.', N'SCHEMA', [Purchasing], N'TABLE', [Vendor], N'TRIGGER', [uVendor];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the VendorAddress table to the current date.', N'SCHEMA', [Purchasing], N'TABLE', [VendorAddress], N'TRIGGER', [uVendorAddress];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the VendorContact table to the current date.', N'SCHEMA', [Purchasing], N'TABLE', [VendorContact], N'TRIGGER', [uVendorContact];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER INSERT trigger that inserts a row in the TransactionHistory table.', N'SCHEMA', [Production], N'TABLE', [WorkOrder], N'TRIGGER', [iWorkOrder];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in the WorkOrder table.', N'SCHEMA', [Production], N'TABLE', [WorkOrder], N'TRIGGER', [uWorkOrder];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'AFTER UPDATE trigger setting the ModifiedDate column in the WorkOrderRouting table to the current date.', N'SCHEMA', [Production], N'TABLE', [WorkOrderRouting], N'TRIGGER', [uWorkOrderRouting];



EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Unique nonclustered index.Used to support replication samples.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'INDEX', [AK_SalesOrderHeader_rowguid];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Unique nonclustered index.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'INDEX', [AK_SalesOrderHeader_SalesOrderNumber];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Nonclustered index.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'INDEX', [IX_SalesOrderHeader_CustomerID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Nonclustered index.>', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'INDEX', [IX_SalesOrderHeader_SalesPersonID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Clustered index created by a primary key constraint.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'INDEX', [PK_SalesOrderHeader_SalesOrderID];



EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Primary key (clustered) constraint', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [PK_SalesOrderHeader_SalesOrderID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing Address.AddressID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_Address_BillToAddressID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing Address.AddressID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_Address_ShipToAddressID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing Contact.ContactID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_Contact_ContactID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing CreditCard.CreditCardID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_CreditCard_CreditCardID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing CurrencyRate.CurrencyRateID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_CurrencyRate_CurrencyRateID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing Customer.CustomerID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_Customer_CustomerID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing SalesPerson.SalesPersonID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_SalesPerson_SalesPersonID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing SalesTerritory.TerritoryID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_SalesTerritory_TerritoryID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Foreign key constraint referencing ShipMethod.ShipMethodID.', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [FK_SalesOrderHeader_ShipMethod_ShipMethodID];
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of 0', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_RevisionNumber]; -- ((0))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of 0.0', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_Freight]; -- ((0.00))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of 0.0', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_SubTotal]; -- ((0.00))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of 0.0', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_TaxAmt]; -- ((0.00))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of 1 (TRUE)', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_OnlineOrderFlag]; -- ((1))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of 1', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_Status]; -- ((1))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of GETDATE()', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_ModifiedDate]; -- (GETDATE())
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of GETDATE()', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_OrderDate]; -- (GETDATE())
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Default constraint value of NEWID()', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [DF_SalesOrderHeader_rowguid]; -- (NEWID())
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Check constraint [Freight]>=(0.00)', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [CK_SalesOrderHeader_Freight]; -- ([Freight]>=(0.00))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Check constraint [SubTotal]>=(0.00)', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [CK_SalesOrderHeader_SubTotal]; -- ([SubTotal]>=(0.00))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Check constraint [TaxAmt]>=(0.00)', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [CK_SalesOrderHeader_TaxAmt]; -- ([TaxAmt]>=(0.00))
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Check constraint [DueDate] >= [OrderDate]', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [CK_SalesOrderHeader_DueDate]; -- ([DueDate]>=[OrderDate])
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Check constraint [ShipDate] >= [OrderDate] OR [ShipDate] IS NULL', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [CK_SalesOrderHeader_ShipDate]; -- ([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL)
EXEC [sys].[sp_addextendedproperty] N'MS_Description', N'Check constraint [Status] BETWEEN (0) AND (8)', N'SCHEMA', [Sales], N'TABLE', [SalesOrderHeader], N'CONSTRAINT', [CK_SalesOrderHeader_Status]; -- ([Status]>=(0) AND [Status]<=(8))
The AdventureWorks database sample was developed by Microsoft Corporation, copyright 2005. SQL Server is a trademark of Microsoft Corporation

Document was prepared on: Thursday, April 05, 2007
Help compiled by DBDocumentor, a Pikauba Software product. All rights reserved.