Northwind Database (Document! X Sample)
Sales.Customer Table
AdventureWorks Database > Sales Schema : Sales.Customer Table
Description
Current customer information. Also see the Person and Store tables.
Properties
Creation Date27/10/2017 14:33
File GroupPRIMARY
Text File Group
System Object
Published for Replication
Rows19820
Data Space Used968.00 KB
Index Space Used1,328.00 KB
Columns
 Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
Primary Key Primary key.Integer4   
 Foreign key to Person.BusinessEntityIDInteger4  
 Foreign key to Store.BusinessEntityIDInteger4  
 ID of the territory in which the customer is located. Foreign key to SalesTerritory.SalesTerritoryID.Integer4  
 Unique number identifying the customer assigned by the accounting system.VarChar10  
(isnull('AW'+[dbo].[ufnLeadingZeros]([CustomerID]),''))
 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. 
Unique nonclustered index. Used to support replication samples. 
Nonclustered index.  
Primary key (clustered) constraint
Relationships
RelationshipDescription
Foreign key constraint referencing Person.BusinessEntityID.
Foreign key constraint referencing SalesTerritory.TerritoryID.
Foreign key constraint referencing Store.BusinessEntityID.
Objects that depend on Sales.Customer
 Database ObjectObject TypeDescriptionDep Level
iduSalesOrderDetail triggeriduSalesOrderDetailTriggerAFTER INSERT, DELETE, UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in SalesOrderDetail and updates the SalesOrderHeader.SubTotal column.2
Sales.SalesOrderDetail tableSales.SalesOrderDetailTableIndividual products associated with a specific sales order. See SalesOrderHeader.1
Sales.SalesOrderHeader tableSales.SalesOrderHeaderTableGeneral sales order information.1
Sales.SalesOrderHeaderSalesReason tableSales.SalesOrderHeaderSalesReasonTableCross-reference table mapping sales orders to sales reason codes.2
dbo.ufnGetContactInformation functiondbo.ufnGetContactInformationUser Defined FunctionTable value function returning the first name, last name, job title and contact type for a given contact.1
uSalesOrderHeader triggeruSalesOrderHeaderTriggerAFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the SalesOrderHeader table.Updates the SalesYTD column in the SalesPerson and SalesTerritory tables.2
Sales.vIndividualCustomer viewSales.vIndividualCustomerViewIndividual customers (names and addresses) that purchase Adventure Works Cycles products online.1
Sales.vSalesPersonSalesByFiscalYears viewSales.vSalesPersonSalesByFiscalYearsViewUses PIVOT to return aggregated sales information for each sales representative.2
Objects that Sales.Customer 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.2
HumanResources.Employee tableHumanResources.EmployeeTableEmployee information such as salary, department, and title.3
dbo.Flag datatypedbo.FlagUser Defined Data Type 4
dbo.Name datatypedbo.NameUser Defined Data Type 2
dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 2
Person.Person tablePerson.PersonTableHuman beings involved with AdventureWorks: employees, customer contacts, and vendor contacts.1
Sales.SalesPerson tableSales.SalesPersonTableSales representative current information.2
Sales.SalesTerritory tableSales.SalesTerritoryTableSales territory lookup table.1
Sales.Store tableSales.StoreTableCustomers (resellers) of Adventure Works products.1
dbo.ufnLeadingZeros functiondbo.ufnLeadingZerosUser Defined FunctionScalar function used by the Sales.Customer table to help set the account number.1
SQL
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE TABLE [Sales].[Customer](
    [CustomerID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    [PersonID] [int] NULL,
    [StoreID] [int] NULL,
    [TerritoryID] [int] NULL,
    [AccountNumber]  AS (isnull('AW'+[dbo].[ufnLeadingZeros]([CustomerID]),'')),
    [rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [ModifiedDate] [datetime] NOT NULL,
 CONSTRAINT [PK_Customer_CustomerID] PRIMARY KEY CLUSTERED 
(
    [CustomerID] 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].[Customer] ADD  CONSTRAINT [DF_Customer_rowguid]  DEFAULT (newid()) FOR [rowguid]
ALTER TABLE [Sales].[Customer] ADD  CONSTRAINT [DF_Customer_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
ALTER TABLE [Sales].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_Person_PersonID] FOREIGN KEY([PersonID])
REFERENCES [Person].[Person] ([BusinessEntityID])
ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_Person_PersonID]
ALTER TABLE [Sales].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID] FOREIGN KEY([TerritoryID])
REFERENCES [Sales].[SalesTerritory] ([TerritoryID])
ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID]
ALTER TABLE [Sales].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_Store_StoreID] FOREIGN KEY([StoreID])
REFERENCES [Sales].[Store] ([BusinessEntityID])
ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_Store_StoreID]
See Also

Related Objects

Sales Schema
AdventureWorks Database