AdventureWorks
Sales.Customer Table
Description
Current customer information. Also see the Individual and Store tables.
Properties
Creation Date08/01/2010 08:40
File GroupPRIMARY
Text File Group
System Object
Published for Replication
Rows19185
Data Space Used824.00 KB
Index Space Used1,176.00 KB
Columns
 Column NameDescriptionDatatypeLengthAllow NullsDefaultFormula
Primary Key CustomerIDPrimary key for Customer records.int4   
 TerritoryIDID of the territory in which the customer is located. Foreign key to SalesTerritory.SalesTerritoryID.int4  
 AccountNumberUnique number identifying the customer assigned by the accounting system.varchar10  
(isnull('AW'+[dbo].[ufnLeadingZeros]([CustomerID]),''))
 CustomerTypeCustomer type: I = Individual, S = Storenchar1   
 rowguidROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.uniqueidentifier16 
(newid())
 
 ModifiedDateDate and time the record was last updated.datetime4 
(getdate())
 
Indexes
IndexDescriptionPrimaryUnique
AK_Customer_AccountNumberUnique nonclustered index. 
AK_Customer_rowguidUnique nonclustered index. Used to support replication samples. 
IX_Customer_TerritoryIDNonclustered index.  
PK_Customer_CustomerIDPrimary key (clustered) constraint
Check Constraints
NameDescriptionExpression
CK_Customer_CustomerTypeCheck constraint [CustomerType]='I' OR [CustomerType]='i' OR [CustomerType]='S' OR [CustomerType]='s'
(upper([CustomerType])='I' OR upper([CustomerType])='S')
Relationships
RelationshipDescription
FK_Customer_SalesTerritory_TerritoryIDForeign key constraint referencing SalesTerritory.TerritoryID.
FK_CustomerAddress_Customer_CustomerIDForeign key constraint referencing Customer.CustomerID.
FK_Individual_Customer_CustomerIDForeign key constraint referencing Customer.CustomerID.
FK_SalesOrderHeader_Customer_CustomerIDForeign key constraint referencing Customer.CustomerID.
FK_Store_Customer_CustomerIDForeign key constraint referencing Customer.CustomerID.
Objects that depend on Sales.Customer
 Database ObjectObject TypeDescriptionDep Level
Sales.CustomerAddress tableSales.CustomerAddressTableCross-reference table mapping customers to their address(es).1
iduSalesOrderDetail triggeriduSalesOrderDetailTriggerAFTER INSERT, DELETE, UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in SalesOrderDetail and updates the SalesOrderHeader.SubTotal column.3
Sales.Individual tableSales.IndividualTableDemographic data about customers that purchase Adventure Works products online.1
iStore triggeriStoreTriggerAFTER INSERT trigger inserting Store only if the Customer does not exist in the Individual table.2
iuIndividual triggeriuIndividualTriggerAFTER 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.2
Sales.SalesOrderDetail tableSales.SalesOrderDetailTableIndividual products associated with a specific sales order. See SalesOrderHeader.2
Sales.SalesOrderHeader tableSales.SalesOrderHeaderTableGeneral sales order information.1
Sales.SalesOrderHeaderSalesReason tableSales.SalesOrderHeaderSalesReasonTableCross-reference table mapping sales orders to sales reason codes.2
Sales.Store tableSales.StoreTableCustomers (resellers) of Adventure Works products.1
Sales.StoreContact tableSales.StoreContactTableCross-reference table mapping stores and their employees.2
dbo.ufnGetContactInformation functiondbo.ufnGetContactInformationUser Defined FunctionTable value function returning the first name, last name, job title and contact type for a given contact.2
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.vIndividualDemographics viewSales.vIndividualDemographicsViewDisplays the content from each element in the xml column Demographics for each customer in the Sales.Individual table.2
Sales.vSalesPersonSalesByFiscalYears viewSales.vSalesPersonSalesByFiscalYearsViewUses PIVOT to return aggregated sales information for each sales representative.2
Sales.vStoreWithDemographics viewSales.vStoreWithDemographicsViewStores (names and addresses) that sell Adventure Works Cycles products to consumers.1
Objects that Sales.Customer depends on
 Database ObjectObject TypeDescriptionDep Level
dbo.Name datatypedbo.NameUser Defined Data Type 2
Sales.SalesTerritory tableSales.SalesTerritoryTableSales territory lookup table.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
SET ARITHABORT ON
CREATE TABLE [Sales].[Customer](
	[CustomerID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[TerritoryID] [int] NULL,
	[AccountNumber]  AS (isnull('AW'+[dbo].[ufnLeadingZeros]([CustomerID]),'')),
	[CustomerType] [nchar](1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[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]  WITH CHECK ADD  CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID] FOREIGN KEY([TerritoryID])
REFERENCES [SalesTerritory] ([TerritoryID])
ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID]
ALTER TABLE [Sales].[Customer]  WITH CHECK ADD  CONSTRAINT [CK_Customer_CustomerType] CHECK  ((upper([CustomerType])='I' OR upper([CustomerType])='S'))
ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [CK_Customer_CustomerType]
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]
See Also

Related Objects

Sales Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.