AdventureWorks database

AdventureWorks Sample OLTP Database

Database server:
Database size: 178.75 MB
Documentation date: 14/07/2008

Tables (70) Views (17 ) Stored procedures (9)
dbo.AWBuildVersion
dbo.DatabaseLog
dbo.ErrorLog
HumanResources.Department (demo version, please register)
HumanResources.Employee (demo version, please register)
HumanResources.EmployeeAddress (demo version, please register)
HumanResources.EmployeeDepartmentHistory (demo version, please register)
HumanResources.EmployeePayHistory (demo version, please register)
HumanResources.JobCandidate (demo version, please register)
HumanResources.Shift (demo version, please register)
Person.Address (demo version, please register)
Person.AddressType (demo version, please register)
Person.Contact (demo version, please register)
Person.ContactType (demo version, please register)
Person.CountryRegion (demo version, please register)
Person.StateProvince (demo version, please register)
Production.BillOfMaterials (demo version, please register)
Production.Culture (demo version, please register)
Production.Document (demo version, please register)
Production.Illustration (demo version, please register)
Production.Location (demo version, please register)
Production.Product (demo version, please register)
Production.ProductCategory (demo version, please register)
Production.ProductCostHistory (demo version, please register)
Production.ProductDescription (demo version, please register)
Production.ProductDocument (demo version, please register)
Production.ProductInventory (demo version, please register)
Production.ProductListPriceHistory (demo version, please register)
Production.ProductModel (demo version, please register)
Production.ProductModelIllustration (demo version, please register)
Production.ProductModelProductDescriptionCulture (demo version, please register)
Production.ProductPhoto (demo version, please register)
Production.ProductProductPhoto (demo version, please register)
Production.ProductReview (demo version, please register)
Production.ProductSubcategory (demo version, please register)
Production.ScrapReason (demo version, please register)
Production.TransactionHistory (demo version, please register)
Production.TransactionHistoryArchive (demo version, please register)
Production.UnitMeasure (demo version, please register)
Production.WorkOrder (demo version, please register)
Production.WorkOrderRouting (demo version, please register)
Purchasing.ProductVendor (demo version, please register)
Purchasing.PurchaseOrderDetail (demo version, please register)
Purchasing.PurchaseOrderHeader (demo version, please register)
Purchasing.ShipMethod (demo version, please register)
Purchasing.Vendor (demo version, please register)
Purchasing.VendorAddress (demo version, please register)
Purchasing.VendorContact (demo version, please register)
Sales.ContactCreditCard (demo version, please register)
Sales.CountryRegionCurrency (demo version, please register)
Sales.CreditCard (demo version, please register)
Sales.Currency (demo version, please register)
Sales.CurrencyRate (demo version, please register)
Sales.Customer (demo version, please register)
Sales.CustomerAddress (demo version, please register)
Sales.Individual (demo version, please register)
Sales.SalesOrderDetail (demo version, please register)
Sales.SalesOrderHeader (demo version, please register)
Sales.SalesOrderHeaderSalesReason (demo version, please register)
Sales.SalesPerson (demo version, please register)
Sales.SalesPersonQuotaHistory (demo version, please register)
Sales.SalesReason (demo version, please register)
Sales.SalesTaxRate (demo version, please register)
Sales.SalesTerritory (demo version, please register)
Sales.SalesTerritoryHistory (demo version, please register)
Sales.ShoppingCartItem (demo version, please register)
Sales.SpecialOffer (demo version, please register)
Sales.SpecialOfferProduct (demo version, please register)
Sales.Store (demo version, please register)
Sales.StoreContact (demo version, please register)
HumanResources.vEmployee
HumanResources.vEmployeeDepartment
HumanResources.vEmployeeDepartmentHistory
HumanResources.vJobCandidate
HumanResources.vJobCandidateEducation
HumanResources.vJobCandidateEmployment
Person.vAdditionalContactInfo
Person.vStateProvinceCountryRegion
Production.vProductAndDescription
Production.vProductModelCatalogDescription
Production.vProductModelInstructions
Purchasing.vVendor
Sales.vIndividualCustomer
Sales.vIndividualDemographics
Sales.vSalesPerson
Sales.vSalesPersonSalesByFiscalYears
Sales.vStoreWithDemographics
dbo.uspGetBillOfMaterials
dbo.uspGetEmployeeManagers
dbo.uspGetManagerEmployees
dbo.uspGetWhereUsedProductID
dbo.uspLogError
dbo.uspPrintError
HumanResources.uspUpdateEmployeeHireInfo
HumanResources.uspUpdateEmployeeLogin
HumanResources.uspUpdateEmployeePersonalInfo

User defined functions (11) User defined data types (6) Users (2) Roles (10)
dbo.ufnGetAccountingEndDate
dbo.ufnGetAccountingStartDate
dbo.ufnGetContactInformation
dbo.ufnGetDocumentStatusText
dbo.ufnGetProductDealerPrice
dbo.ufnGetProductListPrice
dbo.ufnGetProductStandardCost
dbo.ufnGetPurchaseOrderStatusText
dbo.ufnGetSalesOrderStatusText
dbo.ufnGetStock
dbo.ufnLeadingZeros
AccountNumber
Flag
Name
NameStyle
OrderNumber
Phone
dbo
TestUser
db_accessadmin
db_backupoperator
db_datareader
db_datawriter
db_ddladmin
db_denydatareader
db_denydatawriter
db_owner
db_securityadmin
public


(up)

Table: dbo.AWBuildVersion

Current version number of the AdventureWorks sample database.
Field nameData typeNullableDefault valueDescription
PK SystemInformationIDtinyintPrimary key for AWBuildVersion records.
Database Versionnvarchar (25) Version number of the database in 9.yy.mm.dd.00 format.
VersionDatedatetimeDate and time the record was last updated.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
PK_AWBuildVersion_SystemInformationIDSystemInformationIDASCYesCLUSTERED

Table definition

CREATE TABLE [dbo.AWBuildVersion] (
	[SystemInformationID] [tinyint] IDENTITY (1, 1) NOT NULL ,
	[Database Version] [nvarchar] (25) COLLATE Latin1_General_CS_AS NOT NULL ,
	[VersionDate] [datetime] NOT NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_AWBuildVersion_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_AWBuildVersion_SystemInformationID] PRIMARY KEY  CLUSTERED 
	(
		[SystemInformationID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: dbo.DatabaseLog

Audit table tracking all DDL changes made to the AdventureWorks database. Data is captured by the database trigger ddlDatabaseTriggerLog.
Field nameData typeNullableDefault valueDescription
PK DatabaseLogIDintPrimary key for DatabaseLog records.
PostTimedatetimeThe date and time the DDL change occurred.
DatabaseUsernvarchar (128) The user who implemented the DDL change.
Eventnvarchar (128) The type of DDL statement that was executed.
Schemanvarchar (128) YesThe schema to which the changed object belongs.
Objectnvarchar (128) YesThe object that was changed by the DDL statment.
TSQLnvarcharThe exact Transact-SQL statement that was executed.
XmlEventxmlThe raw XML data generated by database trigger.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
PK_DatabaseLog_DatabaseLogIDDatabaseLogIDASCYesNONCLUSTERED

Table definition

CREATE TABLE [dbo.DatabaseLog] (
	[DatabaseLogID] [int] IDENTITY (1, 1) NOT NULL ,
	[PostTime] [datetime] NOT NULL ,
	[DatabaseUser] [sysname] NOT NULL ,
	[Event] [sysname] NOT NULL ,
	[Schema] [sysname] NULL ,
	[Object] [sysname] NULL ,
	[TSQL] [nvarchar] (0) COLLATE Latin1_General_CS_AS NOT NULL ,
	[XmlEvent] [xml] NOT NULL ,
	CONSTRAINT [PK_DatabaseLog_DatabaseLogID] PRIMARY KEY  NONCLUSTERED 
	(
		[DatabaseLogID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: dbo.ErrorLog

Audit 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.
Field nameData typeNullableDefault valueDescription
PK ErrorLogIDintPrimary key for ErrorLog records.
ErrorTimedatetime(getdate())The date and time at which the error occurred.
UserNamenvarchar (128) The user who executed the batch in which the error occurred.
ErrorNumberintThe error number of the error that occurred.
ErrorSeverityintYesThe severity of the error that occurred.
ErrorStateintYesThe state number of the error that occurred.
ErrorProcedurenvarchar (126) YesThe name of the stored procedure or trigger where the error occurred.
ErrorLineintYesThe line number at which the error occurred.
ErrorMessagenvarchar (4000) The message text of the error that occurred.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
PK_ErrorLog_ErrorLogIDErrorLogIDASCYesCLUSTERED

Objects that depend on dbo.ErrorLog:

dbo.uspLogError

Table definition

CREATE TABLE [dbo.ErrorLog] (
	[ErrorLogID] [int] IDENTITY (1, 1) NOT NULL ,
	[ErrorTime] [datetime] NOT NULL CONSTRAINT [DF_ErrorLog_ErrorTime] DEFAULT (getdate()),
	[UserName] [sysname] NOT NULL ,
	[ErrorNumber] [int] NOT NULL ,
	[ErrorSeverity] [int] NULL ,
	[ErrorState] [int] NULL ,
	[ErrorProcedure] [nvarchar] (126) COLLATE Latin1_General_CS_AS NULL ,
	[ErrorLine] [int] NULL ,
	[ErrorMessage] [nvarchar] (4000) COLLATE Latin1_General_CS_AS NOT NULL ,
	CONSTRAINT [PK_ErrorLog_ErrorLogID] PRIMARY KEY  CLUSTERED 
	(
		[ErrorLogID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: HumanResources.Department (demo version, please register)

Lookup table containing the departments within the Adventure Works Cycles company.
Field nameData typeNullableDefault valueDescription
PK DepartmentIDsmallintPrimary key for Department records.
IX NameNameName of the department.
GroupNameNameName of the group to which the department belongs.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_Department_NameNameASCYesNONCLUSTERED
PK_Department_DepartmentIDDepartmentIDASCYesCLUSTERED

Objects that depend on HumanResources.Department (demo version, please register):

HumanResources.vEmployeeDepartment
HumanResources.vEmployeeDepartmentHistory

Table definition

CREATE TABLE [HumanResources.Department] (
	[DepartmentID] [smallint] IDENTITY (1, 1) NOT NULL ,
	[Name] [Name] NOT NULL ,
	[GroupName] [Name] NOT NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Department_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Department_DepartmentID] PRIMARY KEY  CLUSTERED 
	(
		[DepartmentID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: HumanResources.Employee (demo version, please register)

Employee information such as salary, department, and title.
Field nameData typeNullableDefault valueDescription
PK EmployeeIDintPrimary key for Employee records.
IX NationalIDNumbernvarchar (15) Unique national identification number such as a social security number.
FK ContactIDintIdentifies the employee in the Contact table. Foreign key to Contact.ContactID.
IX LoginIDnvarchar (256) Network login.
FK ManagerIDintYesManager to whom the employee is assigned. Foreign Key to Employee.M
Titlenvarchar (50) Work title such as Buyer or Sales Representative.
BirthDatedatetimeDate of birth.
MaritalStatusnchar (1) M = Married, S = Single
Gendernchar (1) M = Male, F = Female
HireDatedatetimeEmployee hired on this date.
SalariedFlagFlag((1))Job classification. 0 = Hourly, not exempt from collective bargaining. 1 = Salaried, exempt from collective bargaining.
VacationHourssmallint((0))Number of available vacation hours.
SickLeaveHourssmallint((0))Number of available sick leave hours.
CurrentFlagFlag((1))0 = Inactive, 1 = Active
IX rowguiduniqueidentifier(newid())ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Foreign keys dependencies:

FK_Employee_Contact_ContactID: ContactID relies upon remote PK_Contact_ContactID (Person.Contact)
FK_Employee_Employee_ManagerID: ManagerID relies upon remote PK_Employee_EmployeeID (HumanResources.Employee)

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_Employee_LoginIDLoginIDASCYesNONCLUSTERED
AK_Employee_NationalIDNumberNationalIDNumberASCYesNONCLUSTERED
AK_Employee_rowguidrowguidASCYesNONCLUSTERED
IX_Employee_ManagerIDManagerIDASCNONCLUSTERED
PK_Employee_EmployeeIDEmployeeIDASCYesCLUSTERED

Check constraints

Check nameColumn nameCheck expresion
CK_Employee_BirthDateBirthDate([BirthDate]>='1930-01-01' AND [BirthDate]<=dateadd(year,(-18),getdate()))
CK_Employee_MaritalStatusMaritalStatus(upper([MaritalStatus])='S' OR upper([MaritalStatus])='M')
CK_Employee_HireDateHireDate([HireDate]>='1996-07-01' AND [HireDate]<=dateadd(day,(1),getdate()))
CK_Employee_GenderGender(upper([Gender])='F' OR upper([Gender])='M')
CK_Employee_VacationHoursVacationHours([VacationHours]>=(-40) AND [VacationHours]<=(240))
CK_Employee_SickLeaveHoursSickLeaveHours([SickLeaveHours]>=(0) AND [SickLeaveHours]<=(120))

Triggers

Trigger name: HumanResources.dEmployee (Created: 26 Apr 2006)
Trigger type: INSTEAD OF DELETE
Trigger active: Yes
Trigger description: INSTEAD OF DELETE trigger which keeps Employees from being deleted.
Trigger definition:

CREATE TRIGGER [HumanResources].[dEmployee] ON [HumanResources].[Employee] 
INSTEAD OF DELETE NOT FOR REPLICATION AS 
BEGIN
    DECLARE @Count int;

    SET @Count = @@ROWCOUNT;
    IF @Count = 0 
        RETURN;

    SET NOCOUNT ON;

    BEGIN
        RAISERROR
            (N'Employees cannot be deleted. They can only be marked as not current.', -- Message
            10, -- Severity.
            1); -- State.

        -- Rollback any active or uncommittable transactions
        IF @@TRANCOUNT > 0
        BEGIN
            ROLLBACK TRANSACTION;
        END
    END;
END;

Objects that depend on HumanResources.Employee (demo version, please register):

dbo.uspGetEmployeeManagers
dbo.uspGetManagerEmployees
HumanResources.uspUpdateEmployeeHireInfo
HumanResources.uspUpdateEmployeeLogin
HumanResources.uspUpdateEmployeePersonalInfo
HumanResources.vEmployee
HumanResources.vEmployeeDepartment
HumanResources.vEmployeeDepartmentHistory
Sales.vSalesPerson
Sales.vSalesPersonSalesByFiscalYears

Table definition

CREATE TABLE [HumanResources.Employee] (
	[EmployeeID] [int] IDENTITY (1, 1) NOT NULL ,
	[NationalIDNumber] [nvarchar] (15) COLLATE Latin1_General_CS_AS NOT NULL ,
	[ContactID] [int] NOT NULL ,
	[LoginID] [nvarchar] (256) COLLATE Latin1_General_CS_AS NOT NULL ,
	[ManagerID] [int] NULL ,
	[Title] [nvarchar] (50) COLLATE Latin1_General_CS_AS NOT NULL ,
	[BirthDate] [datetime] NOT NULL ,
	[MaritalStatus] [nchar] (1) COLLATE Latin1_General_CS_AS NOT NULL ,
	[Gender] [nchar] (1) COLLATE Latin1_General_CS_AS NOT NULL ,
	[HireDate] [datetime] NOT NULL ,
	[SalariedFlag] [Flag] NOT NULL CONSTRAINT [DF_Employee_SalariedFlag] DEFAULT ((1)),
	[VacationHours] [smallint] NOT NULL CONSTRAINT [DF_Employee_VacationHours] DEFAULT ((0)),
	[SickLeaveHours] [smallint] NOT NULL CONSTRAINT [DF_Employee_SickLeaveHours] DEFAULT ((0)),
	[CurrentFlag] [Flag] NOT NULL CONSTRAINT [DF_Employee_CurrentFlag] DEFAULT ((1)),
	[rowguid]  uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_Employee_rowguid] DEFAULT (newid()),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Employee_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Employee_EmployeeID] PRIMARY KEY  CLUSTERED 
	(
		[EmployeeID]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_Employee_Contact_ContactID] FOREIGN KEY 
	(
		[ContactID]
	) REFERENCES [Contact] (
		[ContactID]
	),
	CONSTRAINT [FK_Employee_Employee_ManagerID] FOREIGN KEY 
	(
		[ManagerID]
	) REFERENCES [Employee] (
		[EmployeeID]
	),
	CONSTRAINT [CK_Employee_BirthDate] CHECK ([BirthDate]>='1930-01-01' AND [BirthDate]<=dateadd(year,(-18),getdate())),
	CONSTRAINT [CK_Employee_Gender] CHECK (upper([Gender])='F' OR upper([Gender])='M'),
	CONSTRAINT [CK_Employee_HireDate] CHECK ([HireDate]>='1996-07-01' AND [HireDate]<=dateadd(day,(1),getdate())),
	CONSTRAINT [CK_Employee_MaritalStatus] CHECK (upper([MaritalStatus])='S' OR upper([MaritalStatus])='M'),
	CONSTRAINT [CK_Employee_SickLeaveHours] CHECK ([SickLeaveHours]>=(0) AND [SickLeaveHours]<=(120)),
	CONSTRAINT [CK_Employee_VacationHours] CHECK ([VacationHours]>=(-40) AND [VacationHours]<=(240))
) ON [PRIMARY]
GO




(up)

Table: HumanResources.EmployeeAddress (demo version, please register)

Cross-reference table mapping employees to their address(es).
Field nameData typeNullableDefault valueDescription
PK FKEmployeeIDintPrimary key. Foreign key to Employee.EmployeeID.
PK FKAddressIDintPrimary key. Foreign key to Address.AddressID.
IX rowguiduniqueidentifier(newid())ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Foreign keys dependencies:

FK_EmployeeAddress_Employee_EmployeeID: EmployeeID relies upon remote PK_Employee_EmployeeID (HumanResources.Employee)
FK_EmployeeAddress_Address_AddressID: AddressID relies upon remote PK_Address_AddressID (Person.Address)

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_EmployeeAddress_rowguidrowguidASCYesNONCLUSTERED
PK_EmployeeAddress_EmployeeID_AddressIDEmployeeIDASCYesCLUSTERED
AddressIDASCYesCLUSTERED

Objects that depend on HumanResources.EmployeeAddress (demo version, please register):

HumanResources.vEmployee
Sales.vSalesPerson

Table definition

CREATE TABLE [HumanResources.EmployeeAddress] (
	[EmployeeID] [int] NOT NULL ,
	[AddressID] [int] NOT NULL ,
	[rowguid]  uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_EmployeeAddress_rowguid] DEFAULT (newid()),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_EmployeeAddress_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_EmployeeAddress_EmployeeID_AddressID] PRIMARY KEY  CLUSTERED 
	(
		[EmployeeID],
		[AddressID]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_EmployeeAddress_Address_AddressID] FOREIGN KEY 
	(
		[AddressID]
	) REFERENCES [Address] (
		[AddressID]
	),
	CONSTRAINT [FK_EmployeeAddress_Employee_EmployeeID] FOREIGN KEY 
	(
		[EmployeeID]
	) REFERENCES [Employee] (
		[EmployeeID]
	)
) ON [PRIMARY]
GO




(up)

Table: HumanResources.EmployeeDepartmentHistory (demo version, please register)

Employee department transfers.
Field nameData typeNullableDefault valueDescription
PK FKEmployeeIDintEmployee identification number. Foreign key to Employee.EmployeeID.
PK FKDepartmentIDsmallintDepartment in which the employee worked including currently. Foreign key to Department.DepartmentID.
PK FKShiftIDtinyintIdentifies which 8-hour shift the employee works. Foreign key to Shift.Shift.ID.
PK StartDatedatetimeDate the employee started work in the department.
EndDatedatetimeYesDate the employee left the department. NULL = Current department.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Foreign keys dependencies:

FK_EmployeeDepartmentHistory_Employee_EmployeeID: EmployeeID relies upon remote PK_Employee_EmployeeID (HumanResources.Employee)
FK_EmployeeDepartmentHistory_Department_DepartmentID: DepartmentID relies upon remote PK_Department_DepartmentID (HumanResources.Department)
FK_EmployeeDepartmentHistory_Shift_ShiftID: ShiftID relies upon remote PK_Shift_ShiftID (HumanResources.Shift)

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
IX_EmployeeDepartmentHistory_DepartmentIDDepartmentIDASCNONCLUSTERED
IX_EmployeeDepartmentHistory_ShiftIDShiftIDASCNONCLUSTERED
PK_EmployeeDepartmentHistory_EmployeeID_StartDate_DepartmentIDEmployeeIDASCYesCLUSTERED
DepartmentIDASCYesCLUSTERED
ShiftIDASCYesCLUSTERED
StartDateASCYesCLUSTERED

Check constraints

Check nameColumn nameCheck expresion
CK_EmployeeDepartmentHistory_EndDateStartDate([EndDate]>=[StartDate] OR [EndDate] IS NULL)
CK_EmployeeDepartmentHistory_EndDateEndDate([EndDate]>=[StartDate] OR [EndDate] IS NULL)

Objects that depend on HumanResources.EmployeeDepartmentHistory (demo version, please register):

HumanResources.vEmployeeDepartment
HumanResources.vEmployeeDepartmentHistory

Table definition

CREATE TABLE [HumanResources.EmployeeDepartmentHistory] (
	[EmployeeID] [int] NOT NULL ,
	[DepartmentID] [smallint] NOT NULL ,
	[ShiftID] [tinyint] NOT NULL ,
	[StartDate] [datetime] NOT NULL ,
	[EndDate] [datetime] NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_EmployeeDepartmentHistory_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_EmployeeDepartmentHistory_EmployeeID_StartDate_DepartmentID] PRIMARY KEY  CLUSTERED 
	(
		[EmployeeID],
		[StartDate],
		[DepartmentID],
		[ShiftID]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_EmployeeDepartmentHistory_Department_DepartmentID] FOREIGN KEY 
	(
		[DepartmentID]
	) REFERENCES [Department] (
		[DepartmentID]
	),
	CONSTRAINT [FK_EmployeeDepartmentHistory_Employee_EmployeeID] FOREIGN KEY 
	(
		[EmployeeID]
	) REFERENCES [Employee] (
		[EmployeeID]
	),
	CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID] FOREIGN KEY 
	(
		[ShiftID]
	) REFERENCES [Shift] (
		[ShiftID]
	),
	CONSTRAINT [CK_EmployeeDepartmentHistory_EndDate] CHECK ([EndDate]>=[StartDate] OR [EndDate] IS NULL)
) ON [PRIMARY]
GO




(up)

Table: HumanResources.EmployeePayHistory (demo version, please register)

Employee pay history.
Field nameData typeNullableDefault valueDescription
PK FKEmployeeIDintEmployee identification number. Foreign key to Employee.EmployeeID.
PK RateChangeDatedatetimeDate the change in pay is effective
RatemoneySalary hourly rate.
PayFrequencytinyint1 = Salary received monthly, 2 = Salary received biweekly
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Foreign keys dependencies:

FK_EmployeePayHistory_Employee_EmployeeID: EmployeeID relies upon remote PK_Employee_EmployeeID (HumanResources.Employee)

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
PK_EmployeePayHistory_EmployeeID_RateChangeDateEmployeeIDASCYesCLUSTERED
RateChangeDateASCYesCLUSTERED

Check constraints

Check nameColumn nameCheck expresion
CK_EmployeePayHistory_PayFrequencyPayFrequency([PayFrequency]=(2) OR [PayFrequency]=(1))
CK_EmployeePayHistory_RateRate([Rate]>=(6.50) AND [Rate]<=(200.00))

Objects that depend on HumanResources.EmployeePayHistory (demo version, please register):

HumanResources.uspUpdateEmployeeHireInfo

Table definition

CREATE TABLE [HumanResources.EmployeePayHistory] (
	[EmployeeID] [int] NOT NULL ,
	[RateChangeDate] [datetime] NOT NULL ,
	[Rate] [money] NOT NULL ,
	[PayFrequency] [tinyint] NOT NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_EmployeePayHistory_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_EmployeePayHistory_EmployeeID_RateChangeDate] PRIMARY KEY  CLUSTERED 
	(
		[EmployeeID],
		[RateChangeDate]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_EmployeePayHistory_Employee_EmployeeID] FOREIGN KEY 
	(
		[EmployeeID]
	) REFERENCES [Employee] (
		[EmployeeID]
	),
	CONSTRAINT [CK_EmployeePayHistory_PayFrequency] CHECK ([PayFrequency]=(2) OR [PayFrequency]=(1)),
	CONSTRAINT [CK_EmployeePayHistory_Rate] CHECK ([Rate]>=(6.50) AND [Rate]<=(200.00))
) ON [PRIMARY]
GO




(up)

Table: HumanResources.JobCandidate (demo version, please register)

Résumés submitted to Human Resources by job applicants.
Field nameData typeNullableDefault valueDescription
PK JobCandidateIDintPrimary key for JobCandidate records.
FK EmployeeIDintYesEmployee identification number if applicant was hired. Foreign key to Employee.EmployeeID.
ResumexmlYesRésumé in XML format.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Foreign keys dependencies:

FK_JobCandidate_Employee_EmployeeID: EmployeeID relies upon remote PK_Employee_EmployeeID (HumanResources.Employee)

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
IX_JobCandidate_EmployeeIDEmployeeIDASCNONCLUSTERED
PK_JobCandidate_JobCandidateIDJobCandidateIDASCYesCLUSTERED

Objects that depend on HumanResources.JobCandidate (demo version, please register):

HumanResources.vJobCandidate
HumanResources.vJobCandidateEducation
HumanResources.vJobCandidateEmployment

Table definition

CREATE TABLE [HumanResources.JobCandidate] (
	[JobCandidateID] [int] IDENTITY (1, 1) NOT NULL ,
	[EmployeeID] [int] NULL ,
	[Resume] [xml] NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_JobCandidate_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_JobCandidate_JobCandidateID] PRIMARY KEY  CLUSTERED 
	(
		[JobCandidateID]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_JobCandidate_Employee_EmployeeID] FOREIGN KEY 
	(
		[EmployeeID]
	) REFERENCES [Employee] (
		[EmployeeID]
	)
) ON [PRIMARY]
GO




(up)

Table: HumanResources.Shift (demo version, please register)

Work shift lookup table.
Field nameData typeNullableDefault valueDescription
PK ShiftIDtinyintPrimary key for Shift records.
IX NameNameShift description.
IX StartTimedatetimeShift start time.
IX EndTimedatetimeShift end time.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_Shift_NameNameASCYesNONCLUSTERED
AK_Shift_StartTime_EndTimeStartTimeASCYesNONCLUSTERED
EndTimeASCYesNONCLUSTERED
PK_Shift_ShiftIDShiftIDASCYesCLUSTERED

Objects that depend on HumanResources.Shift (demo version, please register):

HumanResources.vEmployeeDepartmentHistory

Table definition

CREATE TABLE [HumanResources.Shift] (
	[ShiftID] [tinyint] IDENTITY (1, 1) NOT NULL ,
	[Name] [Name] NOT NULL ,
	[StartTime] [datetime] NOT NULL ,
	[EndTime] [datetime] NOT NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Shift_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Shift_ShiftID] PRIMARY KEY  CLUSTERED 
	(
		[ShiftID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: Person.Address (demo version, please register)

Street address information for customers, employees, and vendors.
Field nameData typeNullableDefault valueDescription
PK AddressIDintPrimary key for Address records.
IX AddressLine1nvarchar (60) First street address line.
IX AddressLine2nvarchar (60) YesSecond street address line.
IX Citynvarchar (30) Name of the city.
FK StateProvinceIDintUnique identification number for the state or province. Foreign key to StateProvince table.
IX PostalCodenvarchar (15) Postal code for the street address.
IX rowguiduniqueidentifier(newid())ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Foreign keys dependencies:

FK_Address_StateProvince_StateProvinceID: StateProvinceID relies upon remote PK_StateProvince_StateProvinceID (Person.StateProvince)

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_Address_rowguidrowguidASCYesNONCLUSTERED
IX_Address_AddressLine1_AddressLine2_City_StateProvinceID_PostalCodeAddressLine1ASCYesNONCLUSTERED
AddressLine2ASCYesNONCLUSTERED
CityASCYesNONCLUSTERED
StateProvinceIDASCYesNONCLUSTERED
PostalCodeASCYesNONCLUSTERED
IX_Address_StateProvinceIDStateProvinceIDASCNONCLUSTERED
PK_Address_AddressIDAddressIDASCYesCLUSTERED

Objects that depend on Person.Address (demo version, please register):

HumanResources.vEmployee
Purchasing.vVendor
Sales.vIndividualCustomer
Sales.vSalesPerson
Sales.vStoreWithDemographics

Table definition

CREATE TABLE [Person.Address] (
	[AddressID] [int] IDENTITY (1, 1) NOT FOR REPLICATION  NOT NULL ,
	[AddressLine1] [nvarchar] (60) COLLATE Latin1_General_CS_AS NOT NULL ,
	[AddressLine2] [nvarchar] (60) COLLATE Latin1_General_CS_AS NULL ,
	[City] [nvarchar] (30) COLLATE Latin1_General_CS_AS NOT NULL ,
	[StateProvinceID] [int] NOT NULL ,
	[PostalCode] [nvarchar] (15) COLLATE Latin1_General_CS_AS NOT NULL ,
	[rowguid]  uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_Address_rowguid] DEFAULT (newid()),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Address_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Address_AddressID] PRIMARY KEY  CLUSTERED 
	(
		[AddressID]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_Address_StateProvince_StateProvinceID] FOREIGN KEY 
	(
		[StateProvinceID]
	) REFERENCES [StateProvince] (
		[StateProvinceID]
	)
) ON [PRIMARY]
GO




(up)

Table: Person.AddressType (demo version, please register)

Types of addresses stored in the Address table.
Field nameData typeNullableDefault valueDescription
PK AddressTypeIDintPrimary key for AddressType records.
IX NameNameAddress type description. For example, Billing, Home, or Shipping.
IX rowguiduniqueidentifier(newid())ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_AddressType_NameNameASCYesNONCLUSTERED
AK_AddressType_rowguidrowguidASCYesNONCLUSTERED
PK_AddressType_AddressTypeIDAddressTypeIDASCYesCLUSTERED

Objects that depend on Person.AddressType (demo version, please register):

Sales.vIndividualCustomer
Sales.vStoreWithDemographics

Table definition

CREATE TABLE [Person.AddressType] (
	[AddressTypeID] [int] IDENTITY (1, 1) NOT NULL ,
	[Name] [Name] NOT NULL ,
	[rowguid]  uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_AddressType_rowguid] DEFAULT (newid()),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_AddressType_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_AddressType_AddressTypeID] PRIMARY KEY  CLUSTERED 
	(
		[AddressTypeID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: Person.Contact (demo version, please register)

Names of each employee, customer contact, and vendor contact.
Field nameData typeNullableDefault valueDescription
PK ContactIDintPrimary key for Contact records.
NameStyleNameStyle((0))0 = The data in FirstName and LastName are stored in western style (first name, last name) order. 1 = Eastern style (last name, first name) order.
Titlenvarchar (8) YesA courtesy title. For example, Mr. or Ms.
FirstNameNameFirst name of the person.
MiddleNameNameYesMiddle name or middle initial of the person.
LastNameNameLast name of the person.
Suffixnvarchar (10) YesSurname suffix. For example, Sr. or Jr.
IX EmailAddressnvarchar (50) YesE-mail address for the person.
EmailPromotionint((0))0 = Contact does not wish to receive e-mail promotions, 1 = Contact does wish to receive e-mail promotions from AdventureWorks, 2 = Contact does wish to receive e-mail promotions from AdventureWorks and selected partners.
PhonePhoneYesPhone number associated with the person.
PasswordHashvarchar (128) Password for the e-mail account.
PasswordSaltvarchar (10) Random value concatenated with the password string before the password is hashed.
IX AdditionalContactInfoxmlYesAdditional contact information about the person stored in xml format.
IX rowguiduniqueidentifier(newid())ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_Contact_rowguidrowguidASCYesNONCLUSTERED
IX_Contact_EmailAddressEmailAddressASCNONCLUSTERED
PK_Contact_ContactIDContactIDASCYesCLUSTERED
PXML_Contact_AddContactAdditionalContactInfoASCXML

Check constraints

Check nameColumn nameCheck expresion
CK_Contact_EmailPromotionEmailPromotion([EmailPromotion]>=(0) AND [EmailPromotion]<=(2))

Objects that depend on Person.Contact (demo version, please register):

dbo.uspGetEmployeeManagers
dbo.uspGetManagerEmployees
HumanResources.vEmployee
HumanResources.vEmployeeDepartment
HumanResources.vEmployeeDepartmentHistory
Person.vAdditionalContactInfo
Purchasing.vVendor
Sales.vIndividualCustomer
Sales.vSalesPerson
Sales.vSalesPersonSalesByFiscalYears
Sales.vStoreWithDemographics

Table definition

CREATE TABLE [Person.Contact] (
	[ContactID] [int] IDENTITY (1, 1) NOT FOR REPLICATION  NOT NULL ,
	[NameStyle] [NameStyle] NOT NULL CONSTRAINT [DF_Contact_NameStyle] DEFAULT ((0)),
	[Title] [nvarchar] (8) COLLATE Latin1_General_CS_AS NULL ,
	[FirstName] [Name] NOT NULL ,
	[MiddleName] [Name] NULL ,
	[LastName] [Name] NOT NULL ,
	[Suffix] [nvarchar] (10) COLLATE Latin1_General_CS_AS NULL ,
	[EmailAddress] [nvarchar] (50) COLLATE Latin1_General_CS_AS NULL ,
	[EmailPromotion] [int] NOT NULL CONSTRAINT [DF_Contact_EmailPromotion] DEFAULT ((0)),
	[Phone] [Phone] NULL ,
	[PasswordHash] [varchar] (128) COLLATE Latin1_General_CS_AS NOT NULL ,
	[PasswordSalt] [varchar] (10) COLLATE Latin1_General_CS_AS NOT NULL ,
	[AdditionalContactInfo] [xml] NULL ,
	[rowguid]  uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_Contact_rowguid] DEFAULT (newid()),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Contact_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Contact_ContactID] PRIMARY KEY  CLUSTERED 
	(
		[ContactID]
	)  ON [PRIMARY] ,
	CONSTRAINT [CK_Contact_EmailPromotion] CHECK ([EmailPromotion]>=(0) AND [EmailPromotion]<=(2))
) ON [PRIMARY]
GO




(up)

Table: Person.ContactType (demo version, please register)

Lookup table containing the types of contacts stored in Contact.
Field nameData typeNullableDefault valueDescription
PK ContactTypeIDintPrimary key for ContactType records.
IX NameNameContact type description.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_ContactType_NameNameASCYesNONCLUSTERED
PK_ContactType_ContactTypeIDContactTypeIDASCYesCLUSTERED

Objects that depend on Person.ContactType (demo version, please register):

Purchasing.vVendor
Sales.vStoreWithDemographics

Table definition

CREATE TABLE [Person.ContactType] (
	[ContactTypeID] [int] IDENTITY (1, 1) NOT NULL ,
	[Name] [Name] NOT NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_ContactType_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_ContactType_ContactTypeID] PRIMARY KEY  CLUSTERED 
	(
		[ContactTypeID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: Person.CountryRegion (demo version, please register)

Lookup table containing the ISO standard codes for countries and regions.
Field nameData typeNullableDefault valueDescription
PK CountryRegionCodenvarchar (3) ISO standard code for countries and regions.
IX NameNameCountry or region name.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_CountryRegion_NameNameASCYesNONCLUSTERED
PK_CountryRegion_CountryRegionCodeCountryRegionCodeASCYesCLUSTERED

Objects that depend on Person.CountryRegion (demo version, please register):

HumanResources.vEmployee
Person.vStateProvinceCountryRegion
Purchasing.vVendor
Sales.vIndividualCustomer
Sales.vSalesPerson
Sales.vStoreWithDemographics

Table definition

CREATE TABLE [Person.CountryRegion] (
	[CountryRegionCode] [nvarchar] (3) COLLATE Latin1_General_CS_AS NOT NULL ,
	[Name] [Name] NOT NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_CountryRegion_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_CountryRegion_CountryRegionCode] PRIMARY KEY  CLUSTERED 
	(
		[CountryRegionCode]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: Person.StateProvince (demo version, please register)

State and province lookup table.
Field nameData typeNullableDefault valueDescription
PK StateProvinceIDintPrimary key for StateProvince records.
IX StateProvinceCodenchar (3) ISO standard state or province code.
FK CountryRegionCodenvarchar (3) ISO standard country or region code. Foreign key to CountryRegion.CountryRegionCode.
IsOnlyStateProvinceFlagFlag((1))0 = StateProvinceCode exists. 1 = StateProvinceCode unavailable, using CountryRegionCode.
IX NameNameState or province description.
FK TerritoryIDintID of the territory in which the state or province is located. Foreign key to SalesTerritory.SalesTerritoryID.
IX rowguiduniqueidentifier(newid())ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Foreign keys dependencies:

FK_StateProvince_CountryRegion_CountryRegionCode: CountryRegionCode relies upon remote PK_CountryRegion_CountryRegionCode (Person.CountryRegion)
FK_StateProvince_SalesTerritory_TerritoryID: TerritoryID relies upon remote PK_SalesTerritory_TerritoryID (Sales.SalesTerritory)

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_StateProvince_NameNameASCYesNONCLUSTERED
AK_StateProvince_rowguidrowguidASCYesNONCLUSTERED
AK_StateProvince_StateProvinceCode_CountryRegionCodeStateProvinceCodeASCYesNONCLUSTERED
CountryRegionCodeASCYesNONCLUSTERED
PK_StateProvince_StateProvinceIDStateProvinceIDASCYesCLUSTERED

Objects that depend on Person.StateProvince (demo version, please register):

HumanResources.vEmployee
Person.vStateProvinceCountryRegion
Purchasing.vVendor
Sales.vIndividualCustomer
Sales.vSalesPerson
Sales.vStoreWithDemographics

Table definition

CREATE TABLE [Person.StateProvince] (
	[StateProvinceID] [int] IDENTITY (1, 1) NOT NULL ,
	[StateProvinceCode] [nchar] (3) COLLATE Latin1_General_CS_AS NOT NULL ,
	[CountryRegionCode] [nvarchar] (3) COLLATE Latin1_General_CS_AS NOT NULL ,
	[IsOnlyStateProvinceFlag] [Flag] NOT NULL CONSTRAINT [DF_StateProvince_IsOnlyStateProvinceFlag] DEFAULT ((1)),
	[Name] [Name] NOT NULL ,
	[TerritoryID] [int] NOT NULL ,
	[rowguid]  uniqueidentifier ROWGUIDCOL  NOT NULL CONSTRAINT [DF_StateProvince_rowguid] DEFAULT (newid()),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_StateProvince_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_StateProvince_StateProvinceID] PRIMARY KEY  CLUSTERED 
	(
		[StateProvinceID]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_StateProvince_CountryRegion_CountryRegionCode] FOREIGN KEY 
	(
		[CountryRegionCode]
	) REFERENCES [CountryRegion] (
		[CountryRegionCode]
	),
	CONSTRAINT [FK_StateProvince_SalesTerritory_TerritoryID] FOREIGN KEY 
	(
		[TerritoryID]
	) REFERENCES [SalesTerritory] (
		[TerritoryID]
	)
) ON [PRIMARY]
GO




(up)

Table: Production.BillOfMaterials (demo version, please register)

Items required to make bicycles and bicycle subassemblies. It identifies the heirarchical relationship between a parent product and its components.
Field nameData typeNullableDefault valueDescription
PK BillOfMaterialsIDintPrimary key for BillOfMaterials records.
FK ProductAssemblyIDintYesParent product identification number. Foreign key to Product.ProductID.
FK ComponentIDintComponent identification number. Foreign key to Product.ProductID.
IX StartDatedatetime(getdate())Date the component started being used in the assembly item.
EndDatedatetimeYesDate the component stopped being used in the assembly item.
FK UnitMeasureCodenchar (3) Standard code identifying the unit of measure for the quantity.
BOMLevelsmallintIndicates the depth the component is from its parent (AssemblyID).
PerAssemblyQtydecimal (8.2) ((1.00))Quantity of the component needed to create the assembly.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Foreign keys dependencies:

FK_BillOfMaterials_Product_ProductAssemblyID: ProductAssemblyID relies upon remote PK_Product_ProductID (Production.Product)
FK_BillOfMaterials_Product_ComponentID: ComponentID relies upon remote PK_Product_ProductID (Production.Product)
FK_BillOfMaterials_UnitMeasure_UnitMeasureCode: UnitMeasureCode relies upon remote PK_UnitMeasure_UnitMeasureCode (Production.UnitMeasure)

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDateProductAssemblyIDASCYesCLUSTERED
ComponentIDASCYesCLUSTERED
StartDateASCYesCLUSTERED
IX_BillOfMaterials_UnitMeasureCodeUnitMeasureCodeASCNONCLUSTERED
PK_BillOfMaterials_BillOfMaterialsIDBillOfMaterialsIDASCYesNONCLUSTERED

Check constraints

Check nameColumn nameCheck expresion
CK_BillOfMaterials_EndDateStartDate([EndDate]>[StartDate] OR [EndDate] IS NULL)
CK_BillOfMaterials_EndDateEndDate([EndDate]>[StartDate] OR [EndDate] IS NULL)
CK_BillOfMaterials_ProductAssemblyIDProductAssemblyID([ProductAssemblyID]<>[ComponentID])
CK_BillOfMaterials_ProductAssemblyIDComponentID([ProductAssemblyID]<>[ComponentID])
CK_BillOfMaterials_BOMLevelProductAssemblyID([ProductAssemblyID] IS NULL AND [BOMLevel]=(0) AND [PerAssemblyQty]=(1.00) OR [ProductAssemblyID] IS NOT NULL AND [BOMLevel]>=(1))
CK_BillOfMaterials_BOMLevelBOMLevel([ProductAssemblyID] IS NULL AND [BOMLevel]=(0) AND [PerAssemblyQty]=(1.00) OR [ProductAssemblyID] IS NOT NULL AND [BOMLevel]>=(1))
CK_BillOfMaterials_BOMLevelPerAssemblyQty([ProductAssemblyID] IS NULL AND [BOMLevel]=(0) AND [PerAssemblyQty]=(1.00) OR [ProductAssemblyID] IS NOT NULL AND [BOMLevel]>=(1))
CK_BillOfMaterials_PerAssemblyQtyPerAssemblyQty([PerAssemblyQty]>=(1.00))

Objects that depend on Production.BillOfMaterials (demo version, please register):

dbo.uspGetBillOfMaterials
dbo.uspGetWhereUsedProductID

Table definition

CREATE TABLE [Production.BillOfMaterials] (
	[BillOfMaterialsID] [int] IDENTITY (1, 1) NOT NULL ,
	[ProductAssemblyID] [int] NULL ,
	[ComponentID] [int] NOT NULL ,
	[StartDate] [datetime] NOT NULL CONSTRAINT [DF_BillOfMaterials_StartDate] DEFAULT (getdate()),
	[EndDate] [datetime] NULL ,
	[UnitMeasureCode] [nchar] (3) COLLATE Latin1_General_CS_AS NOT NULL ,
	[BOMLevel] [smallint] NOT NULL ,
	[PerAssemblyQty] [decimal](8, 2) NOT NULL CONSTRAINT [DF_BillOfMaterials_PerAssemblyQty] DEFAULT ((1.00)),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_BillOfMaterials_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_BillOfMaterials_BillOfMaterialsID] PRIMARY KEY  NONCLUSTERED 
	(
		[BillOfMaterialsID]
	)  ON [PRIMARY] ,
	CONSTRAINT [FK_BillOfMaterials_Product_ComponentID] FOREIGN KEY 
	(
		[ComponentID]
	) REFERENCES [Product] (
		[ProductID]
	),
	CONSTRAINT [FK_BillOfMaterials_Product_ProductAssemblyID] FOREIGN KEY 
	(
		[ProductAssemblyID]
	) REFERENCES [Product] (
		[ProductID]
	),
	CONSTRAINT [FK_BillOfMaterials_UnitMeasure_UnitMeasureCode] FOREIGN KEY 
	(
		[UnitMeasureCode]
	) REFERENCES [UnitMeasure] (
		[UnitMeasureCode]
	),
	CONSTRAINT [CK_BillOfMaterials_BOMLevel] CHECK ([ProductAssemblyID] IS NULL AND [BOMLevel]=(0) AND [PerAssemblyQty]=(1.00) OR [ProductAssemblyID] IS NOT NULL AND [BOMLevel]>=(1)),
	CONSTRAINT [CK_BillOfMaterials_EndDate] CHECK ([EndDate]>[StartDate] OR [EndDate] IS NULL),
	CONSTRAINT [CK_BillOfMaterials_PerAssemblyQty] CHECK ([PerAssemblyQty]>=(1.00)),
	CONSTRAINT [CK_BillOfMaterials_ProductAssemblyID] CHECK ([ProductAssemblyID]<>[ComponentID])
) ON [PRIMARY]
GO




(up)

Table: Production.Culture (demo version, please register)

Lookup table containing the languages in which some AdventureWorks data is stored.
Field nameData typeNullableDefault valueDescription
PK CultureIDnchar (6) Primary key for Culture records.
IX NameNameCulture description.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_Culture_NameNameASCYesNONCLUSTERED
PK_Culture_CultureIDCultureIDASCYesCLUSTERED

Table definition

CREATE TABLE [Production.Culture] (
	[CultureID] [nchar] (6) COLLATE Latin1_General_CS_AS NOT NULL ,
	[Name] [Name] NOT NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Culture_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Culture_CultureID] PRIMARY KEY  CLUSTERED 
	(
		[CultureID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: Production.Document (demo version, please register)

Product maintenance documents.
Field nameData typeNullableDefault valueDescription
PK DocumentIDintPrimary key for Document records.
Titlenvarchar (50) Title of the document.
IX FileNamenvarchar (400) Directory path and file name of the document
FileExtensionnvarchar (8) File extension indicating the document type. For example, .doc or .txt.
IX Revisionnchar (5) Revision number of the document.
ChangeNumberint((0))Engineering change approval number.
Statustinyint1 = Pending approval, 2 = Approved, 3 = Obsolete
DocumentSummarynvarcharYesDocument abstract.
DocumentvarbinaryYesComplete document.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_Document_FileName_RevisionFileNameASCYesNONCLUSTERED
RevisionASCYesNONCLUSTERED
PK_Document_DocumentIDDocumentIDASCYesCLUSTERED

Check constraints

Check nameColumn nameCheck expresion
CK_Document_StatusStatus([Status]>=(1) AND [Status]<=(3))

Table definition

CREATE TABLE [Production.Document] (
	[DocumentID] [int] IDENTITY (1, 1) NOT NULL ,
	[Title] [nvarchar] (50) COLLATE Latin1_General_CS_AS NOT NULL ,
	[FileName] [nvarchar] (400) COLLATE Latin1_General_CS_AS NOT NULL ,
	[FileExtension] [nvarchar] (8) COLLATE Latin1_General_CS_AS NOT NULL ,
	[Revision] [nchar] (5) COLLATE Latin1_General_CS_AS NOT NULL ,
	[ChangeNumber] [int] NOT NULL CONSTRAINT [DF_Document_ChangeNumber] DEFAULT ((0)),
	[Status] [tinyint] NOT NULL ,
	[DocumentSummary] [nvarchar] (0) COLLATE Latin1_General_CS_AS NULL ,
	[Document] [varbinary] (-1) NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Document_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Document_DocumentID] PRIMARY KEY  CLUSTERED 
	(
		[DocumentID]
	)  ON [PRIMARY] ,
	CONSTRAINT [CK_Document_Status] CHECK ([Status]>=(1) AND [Status]<=(3))
) ON [PRIMARY]
GO




(up)

Table: Production.Illustration (demo version, please register)

Bicycle assembly diagrams.
Field nameData typeNullableDefault valueDescription
PK IllustrationIDintPrimary key for Illustration records.
DiagramxmlYesIllustrations used in manufacturing instructions. Stored as XML.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
PK_Illustration_IllustrationIDIllustrationIDASCYesCLUSTERED

Table definition

CREATE TABLE [Production.Illustration] (
	[IllustrationID] [int] IDENTITY (1, 1) NOT NULL ,
	[Diagram] [xml] NULL ,
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Illustration_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Illustration_IllustrationID] PRIMARY KEY  CLUSTERED 
	(
		[IllustrationID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO




(up)

Table: Production.Location (demo version, please register)

Product inventory and manufacturing locations.
Field nameData typeNullableDefault valueDescription
PK LocationIDsmallintPrimary key for Location records.
IX NameNameLocation description.
CostRatesmallmoney((0.00))Standard hourly cost of the manufacturing location.
Availabilitydecimal (8.2) ((0.00))Work capacity (in hours) of the manufacturing location.
ModifiedDatedatetime(getdate())Date and time the record was last updated.

Indexes

Index nameColumn nameSort directionIs uniqueIndex type
AK_Location_NameNameASCYesNONCLUSTERED
PK_Location_LocationIDLocationIDASCYesCLUSTERED

Check constraints

Check nameColumn nameCheck expresion
CK_Location_CostRateCostRate([CostRate]>=(0.00))
CK_Location_AvailabilityAvailability([Availability]>=(0.00))

Table definition

CREATE TABLE [Production.Location] (
	[LocationID] [smallint] IDENTITY (1, 1) NOT NULL ,
	[Name] [Name] NOT NULL ,
	[CostRate] [smallmoney] NOT NULL CONSTRAINT [DF_Location_CostRate] DEFAULT ((0.00)),
	[Availability] [decimal](8, 2) NOT NULL CONSTRAINT [DF_Location_Availability] DEFAULT ((0.00)),
	[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Location_ModifiedDate] DEFAULT (getdate()),
	CONSTRAINT [PK_Location_LocationID] PRIMARY KEY  CLUSTERED 
	(
		[LocationID]
	)  ON [PRIMARY] ,
	CONSTRAINT [CK_Location_Availability] CHECK ([Availability]>=(0.00)),
	CONSTRAINT [CK_Location_CostRate] CHECK ([CostRate]>=(0.00))
) ON [PRIMARY]
GO




(up)

Table: Production.Product (demo version, please register)

Products sold or used in the manfacturing of sold products.
Field nameData typeNullableDefault valueDescription
PK ProductIDintPrimary key for Product records.
IX NameNameName of the product.
IX ProductNumbernvarchar (25) Unique product identification number.
MakeFlagFlag((1))0 = Product is purchased, 1 = Product is manufactured in-house.
FinishedGoodsFlagFlag((1))0 = Product is not a salable item. 1 = Product is salable.
Colornvarchar (15) YesProduct color.
SafetyStockLevelsmallintMinimum inventory quantity.
ReorderPointsmallintInventory level that triggers a purchase order or work order.
StandardCostmoneyStandard cost of the product.
ListPricemoneySelling price.
Sizenvarchar (5) YesProduct size.
FK SizeUnitMeasureCodenchar (3) YesUnit of measure for Size column.
FK WeightUnitMeasureCodenchar (3) YesUnit of measure for Weight column.
Weightdecimal (8.2) YesProduct weight.
DaysToManufactureintNumber of days required to manufacture the product.
ProductLinenchar (2) YesR = Road, M = Mountain, T = Touring, S = Standard
Classnchar (2) YesH = High, M = Medium, L = Low
Stylenchar (2) YesW = Womens, M = Mens, U = Universal