Northwind Database (Document! X Sample)
AdventureWorks Database / Sales Schema / Sales.SalesTerritoryHistory Table
In This Topic
    Sales.SalesTerritoryHistory Table
    In This Topic
    Description
    Sales representative transfers to other sales territories.
    Properties
    Creation Date27/10/2017 14:33
    File GroupPRIMARY
    Text File Group
    System Object
    Published for Replication
    Rows17
    Data Space Used8.00 KB
    Index Space Used24.00 KB
    Columns
     Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
    Primary Key Primary key. The sales rep. Foreign key to SalesPerson.BusinessEntityID.Integer4   
    Primary Key Primary key. Territory identification number. Foreign key to SalesTerritory.SalesTerritoryID.Integer4   
    Primary Key Primary key. Date the sales representive started work in the territory.DBTimeStamp4   
     Date the sales representative left work in the territory.DBTimeStamp4  
     ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.GUID16 
    (newid())
     
     Date and time the record was last updated.DBTimeStamp4 
    (getdate())
     
    Indexes
    IndexDescriptionPrimaryUnique
    Unique nonclustered index. Used to support replication samples. 
    Primary key (clustered) constraint
    Check Constraints
    NameDescriptionExpression
    Check constraint [EndDate] >= [StartDate] OR [EndDate] IS NULL
    ([EndDate]>=[StartDate] OR [EndDate] IS NULL)
    Relationships
    RelationshipDescription
    Foreign key constraint referencing SalesPerson.SalesPersonID.
    Foreign key constraint referencing SalesTerritory.TerritoryID.
    Objects that Sales.SalesTerritoryHistory depends on
     Database ObjectObject TypeDescriptionDep Level
    Person.BusinessEntity tablePerson.BusinessEntityTableSource of the ID that connects vendors, customers, and employees with address and contact information.2
    Person.CountryRegion tablePerson.CountryRegionTableLookup table containing the ISO standard codes for countries and regions.4
    HumanResources.Employee tableHumanResources.EmployeeTableEmployee information such as salary, department, and title.3
    dbo.Flag datatypedbo.FlagUser Defined Data Type 4
    dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 5
    Person.Person tablePerson.PersonTableHuman beings involved with AdventureWorks: employees, customer contacts, and vendor contacts.4
    Sales.SalesPerson tableSales.SalesPersonTableSales representative current information.2
    Sales.SalesTerritory tableSales.SalesTerritoryTableSales territory lookup table.3
    SQL
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [Sales].[SalesTerritoryHistory](
        [BusinessEntityID] [int] NOT NULL,
        [TerritoryID] [int] NOT NULL,
        [StartDate] [datetime] NOT NULL,
        [EndDate] [datetime] NULL,
        [rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
        [ModifiedDate] [datetime] NOT NULL,
     CONSTRAINT [PK_SalesTerritoryHistory_BusinessEntityID_StartDate_TerritoryID] PRIMARY KEY CLUSTERED 
    (
        [BusinessEntityID] ASC,
        [StartDate] ASC,
        [TerritoryID] 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].[SalesTerritoryHistory] ADD  CONSTRAINT [DF_SalesTerritoryHistory_rowguid]  DEFAULT (newid()) FOR [rowguid]
    ALTER TABLE [Sales].[SalesTerritoryHistory] ADD  CONSTRAINT [DF_SalesTerritoryHistory_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
    ALTER TABLE [Sales].[SalesTerritoryHistory]  WITH CHECK ADD  CONSTRAINT [FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID] FOREIGN KEY([BusinessEntityID])
    REFERENCES [Sales].[SalesPerson] ([BusinessEntityID])
    ALTER TABLE [Sales].[SalesTerritoryHistory] CHECK CONSTRAINT [FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID]
    ALTER TABLE [Sales].[SalesTerritoryHistory]  WITH CHECK ADD  CONSTRAINT [FK_SalesTerritoryHistory_SalesTerritory_TerritoryID] FOREIGN KEY([TerritoryID])
    REFERENCES [Sales].[SalesTerritory] ([TerritoryID])
    ALTER TABLE [Sales].[SalesTerritoryHistory] CHECK CONSTRAINT [FK_SalesTerritoryHistory_SalesTerritory_TerritoryID]
    ALTER TABLE [Sales].[SalesTerritoryHistory]  WITH CHECK ADD  CONSTRAINT [CK_SalesTerritoryHistory_EndDate] CHECK  (([EndDate]>=[StartDate] OR [EndDate] IS NULL))
    ALTER TABLE [Sales].[SalesTerritoryHistory] CHECK CONSTRAINT [CK_SalesTerritoryHistory_EndDate]
    See Also