Northwind Database (Document! X Sample)
AdventureWorks Database / Sales Schema / Sales.SalesOrderHeaderSalesReason Table
In This Topic
    Sales.SalesOrderHeaderSalesReason Table
    In This Topic
    Description
    Cross-reference table mapping sales orders to sales reason codes.
    Properties
    Creation Date27/10/2017 14:33
    File GroupPRIMARY
    Text File Group
    System Object
    Published for Replication
    Rows27647
    Data Space Used688.00 KB
    Index Space Used16.00 KB
    Columns
     Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
    Primary Key Primary key. Foreign key to SalesOrderHeader.SalesOrderID.Integer4   
    Primary Key Primary key. Foreign key to SalesReason.SalesReasonID.Integer4   
     Date and time the record was last updated.DBTimeStamp4 
    (getdate())
     
    Indexes
    IndexDescriptionPrimaryUnique
    Primary key (clustered) constraint
    Relationships
    RelationshipDescription
    Foreign key constraint referencing SalesOrderHeader.SalesOrderID.
    Foreign key constraint referencing SalesReason.SalesReasonID.
    Objects that Sales.SalesOrderHeaderSalesReason 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.1
    Person.BusinessEntity tablePerson.BusinessEntityTableSource of the ID that connects vendors, customers, and employees with address and contact information.2
    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 Person 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.3
    dbo.Flag datatypedbo.FlagUser Defined Data Type 4
    dbo.Name datatypedbo.NameUser Defined Data Type 2
    dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 5
    dbo.OrderNumber datatypedbo.OrderNumberUser Defined Data Type 2
    Person.Person tablePerson.PersonTableHuman beings involved with AdventureWorks: employees, customer contacts, and vendor contacts.4
    Sales.SalesOrderHeader tableSales.SalesOrderHeaderTableGeneral sales order information.1
    Sales.SalesPerson tableSales.SalesPersonTableSales representative current information.2
    Sales.SalesReason tableSales.SalesReasonTableLookup table of customer purchase reasons.1
    Sales.SalesTerritory tableSales.SalesTerritoryTableSales territory lookup table.3
    Purchasing.ShipMethod tablePurchasing.ShipMethodTableShipping company lookup table.2
    Person.StateProvince tablePerson.StateProvinceTableState and province lookup table.1
    Sales.Store tableSales.StoreTableCustomers (resellers) of Adventure Works products.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
    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.2
    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.2
    SQL
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [Sales].[SalesOrderHeaderSalesReason](
        [SalesOrderID] [int] NOT NULL,
        [SalesReasonID] [int] NOT NULL,
        [ModifiedDate] [datetime] NOT NULL,
     CONSTRAINT [PK_SalesOrderHeaderSalesReason_SalesOrderID_SalesReasonID] PRIMARY KEY CLUSTERED 
    (
        [SalesOrderID] ASC,
        [SalesReasonID] 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].[SalesOrderHeaderSalesReason] ADD  CONSTRAINT [DF_SalesOrderHeaderSalesReason_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
    ALTER TABLE [Sales].[SalesOrderHeaderSalesReason]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID] FOREIGN KEY([SalesOrderID])
    REFERENCES [Sales].[SalesOrderHeader] ([SalesOrderID])
    ON DELETE CASCADE
    ALTER TABLE [Sales].[SalesOrderHeaderSalesReason] CHECK CONSTRAINT [FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID]
    ALTER TABLE [Sales].[SalesOrderHeaderSalesReason]  WITH CHECK ADD  CONSTRAINT [FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID] FOREIGN KEY([SalesReasonID])
    REFERENCES [Sales].[SalesReason] ([SalesReasonID])
    ALTER TABLE [Sales].[SalesOrderHeaderSalesReason] CHECK CONSTRAINT [FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID]
    See Also