Lookup table containing the departments within the Adventure Works Cycles company.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | DepartmentID | smallint NOT NULL IDENTITY | Primary key for Department records. |
| * | Name | HumanResources.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Name of the department. |
| * | GroupName | HumanResources.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Name of the group to which the department belongs. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Department_DepartmentID | Primary Key ON DepartmentID | ||
| AK_Department_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_EmployeeDepartmentHistory_Department_DepartmentID | DepartmentID ↙ ❏ HumanResources.EmployeeDepartmentHistory | ||
Employee information such as salary, department, and title.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key for Employee records. Foreign key to BusinessEntity.BusinessEntityID. |
| * | NationalIDNumber | nvarchar(15) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Unique national identification number such as a social security number. |
| * | LoginID | nvarchar(256) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Network login. |
| OrganizationNode | hierarchyid | Where the employee is located in corporate hierarchy. | |
| OrganizationLevel | text | The depth of the employee in the corporate hierarchy. | |
| * | JobTitle | nvarchar(50) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Work title such as Buyer or Sales Representative. |
| * | BirthDate | date NOT NULL | Date of birth. |
| * | MaritalStatus | nchar(1) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | M = Married, S = Single |
| * | Gender | nchar(1) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | M = Male, F = Female |
| * | HireDate | date NOT NULL | Employee hired on this date. |
| * | SalariedFlag | HumanResources.Flag NOT NULL DEFAULT ((1)) | Job classification. 0 = Hourly, not exempt from collective bargaining. 1 = Salaried, exempt from collective bargaining. |
| * | VacationHours | smallint NOT NULL DEFAULT 0 | Number of available vacation hours. |
| * | SickLeaveHours | smallint NOT NULL DEFAULT 0 | Number of available sick leave hours. |
| * | CurrentFlag | HumanResources.Flag NOT NULL DEFAULT ((1)) | 0 = Inactive, 1 = Active |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Employee_BusinessEntityID | Primary Key ON BusinessEntityID | ||
| AK_Employee_LoginID | Unique Index ON LoginID | ||
| AK_Employee_NationalIDNumber | Unique Index ON NationalIDNumber | ||
| AK_Employee_rowguid | Unique Index ON rowguid | ||
| IX_Employee_OrganizationNode | Index ON OrganizationNode | ||
| IX_Employee_OrganizationLevel_OrganizationNode | Index ON OrganizationLevel, OrganizationNode | ||
| Foreign Key | |||
| FK_Employee_Person_BusinessEntityID | BusinessEntityID ↗ ❏ Person.Person | ||
| Referring Foreign Key | |||
| FK_EmployeeDepartmentHistory_Employee_BusinessEntityID | BusinessEntityID ↙ ❏ HumanResources.EmployeeDepartmentHistory | ||
| FK_EmployeePayHistory_Employee_BusinessEntityID | BusinessEntityID ↙ ❏ HumanResources.EmployeePayHistory | ||
| FK_JobCandidate_Employee_BusinessEntityID | BusinessEntityID ↙ ❏ HumanResources.JobCandidate | ||
| FK_Document_Employee_Owner | BusinessEntityID ↙ ❏ Production.Document(Owner) | ||
| FK_PurchaseOrderHeader_Employee_EmployeeID | BusinessEntityID ↙ ❏ Purchasing.PurchaseOrderHeader(EmployeeID) | ||
| FK_SalesPerson_Employee_BusinessEntityID | BusinessEntityID ↙ ❏ Sales.SalesPerson | ||
| Constraints | |||
| CK_Employee_BirthDate | [BirthDate]>='1930-01-01' AND [BirthDate]<=dateadd(year,(-18),getdate()) | ||
| CK_Employee_MaritalStatus | upper([MaritalStatus])='S' OR upper([MaritalStatus])='M' | ||
| CK_Employee_HireDate | [HireDate]>='1996-07-01' AND [HireDate]<=dateadd(day,(1),getdate()) | ||
| CK_Employee_Gender | upper([Gender])='F' OR upper([Gender])='M' | ||
| CK_Employee_VacationHours | [VacationHours]>=(-40) AND [VacationHours]<=(240) | ||
| CK_Employee_SickLeaveHours | [SickLeaveHours]>=(0) AND [SickLeaveHours]<=(120) | ||
| Triggers | |||
| dEmployee | CREATE TRIGGER [HumanResources].[${nameWithSchemaName}] 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 | ||
Employee department transfers.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Employee identification number. Foreign key to Employee.BusinessEntityID. |
| * | DepartmentID | smallint NOT NULL | Department in which the employee worked including currently. Foreign key to Department.DepartmentID. |
| * | ShiftID | tinyint NOT NULL | Identifies which 8-hour shift the employee works. Foreign key to Shift.Shift.ID. |
| * | StartDate | date NOT NULL | Date the employee started work in the department. |
| EndDate | date | Date the employee left the department. NULL = Current department. | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_EmployeeDepartmentHistory_BusinessEntityID_StartDate_DepartmentID | Primary Key ON BusinessEntityID, StartDate, DepartmentID, ShiftID | ||
| IX_EmployeeDepartmentHistory_DepartmentID | Index ON DepartmentID | ||
| IX_EmployeeDepartmentHistory_ShiftID | Index ON ShiftID | ||
| Foreign Key | |||
| FK_EmployeeDepartmentHistory_Department_DepartmentID | DepartmentID ↗ ❏ HumanResources.Department | ||
| FK_EmployeeDepartmentHistory_Employee_BusinessEntityID | BusinessEntityID ↗ ❏ HumanResources.Employee | ||
| FK_EmployeeDepartmentHistory_Shift_ShiftID | ShiftID ↗ ❏ HumanResources.Shift | ||
| Constraints | |||
| CK_EmployeeDepartmentHistory_EndDate | [EndDate]>=[StartDate] OR [EndDate] IS NULL | ||
Employee pay history.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Employee identification number. Foreign key to Employee.BusinessEntityID. |
| * | RateChangeDate | datetime NOT NULL | Date the change in pay is effective |
| * | Rate | money NOT NULL | Salary hourly rate. |
| * | PayFrequency | tinyint NOT NULL | 1 = Salary received monthly, 2 = Salary received biweekly |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_EmployeePayHistory_BusinessEntityID_RateChangeDate | Primary Key ON BusinessEntityID, RateChangeDate | ||
| Foreign Key | |||
| FK_EmployeePayHistory_Employee_BusinessEntityID | BusinessEntityID ↗ ❏ HumanResources.Employee | ||
| Constraints | |||
| CK_EmployeePayHistory_PayFrequency | [PayFrequency]=(2) OR [PayFrequency]=(1) | ||
| CK_EmployeePayHistory_Rate | [Rate]>=(6.50) AND [Rate]<=(200.00) | ||
Résumés submitted to Human Resources by job applicants.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | JobCandidateID | int NOT NULL IDENTITY | Primary key for JobCandidate records. |
| BusinessEntityID | int | Employee identification number if applicant was hired. Foreign key to Employee.BusinessEntityID. | |
| Resume | xml | Résumé in XML format. | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_JobCandidate_JobCandidateID | Primary Key ON JobCandidateID | ||
| IX_JobCandidate_BusinessEntityID | Index ON BusinessEntityID | ||
| Foreign Key | |||
| FK_JobCandidate_Employee_BusinessEntityID | BusinessEntityID ↗ ❏ HumanResources.Employee | ||
Work shift lookup table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ShiftID | tinyint NOT NULL IDENTITY | Primary key for Shift records. |
| * | Name | HumanResources.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Shift description. |
| * | StartTime | time NOT NULL | Shift start time. |
| * | EndTime | time NOT NULL | Shift end time. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Shift_ShiftID | Primary Key ON ShiftID | ||
| AK_Shift_Name | Unique Index ON Name | ||
| AK_Shift_StartTime_EndTime | Unique Index ON StartTime, EndTime | ||
| Referring Foreign Key | |||
| FK_EmployeeDepartmentHistory_Shift_ShiftID | ShiftID ↙ ❏ HumanResources.EmployeeDepartmentHistory | ||
Street address information for customers, employees, and vendors.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | AddressID | int NOT NULL IDENTITY | Primary key for Address records. |
| * | AddressLine1 | nvarchar(60) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | First street address line. |
| AddressLine2 | nvarchar(60) COLLATE SQL_Latin1_General_CP1_CI_AS | Second street address line. | |
| * | City | nvarchar(30) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Name of the city. |
| * | StateProvinceID | int NOT NULL | Unique identification number for the state or province. Foreign key to StateProvince table. |
| * | PostalCode | nvarchar(15) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Postal code for the street address. |
| SpatialLocation | geography | Latitude and longitude of this address. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Address_AddressID | Primary Key ON AddressID | ||
| AK_Address_rowguid | Unique Index ON rowguid | ||
| IX_Address_AddressLine1_AddressLine2_City_StateProvinceID_PostalCode | Unique Index ON AddressLine1, AddressLine2, City, StateProvinceID, PostalCode | ||
| IX_Address_StateProvinceID | Index ON StateProvinceID | ||
| Foreign Key | |||
| FK_Address_StateProvince_StateProvinceID | StateProvinceID ↗ ❏ Person.StateProvince | ||
| Referring Foreign Key | |||
| FK_BusinessEntityAddress_Address_AddressID | AddressID ↙ ❏ Person.BusinessEntityAddress | ||
| FK_SalesOrderHeader_Address_BillToAddressID | AddressID ↙ ❏ Sales.SalesOrderHeader(BillToAddressID) | ||
| FK_SalesOrderHeader_Address_ShipToAddressID | AddressID ↙ ❏ Sales.SalesOrderHeader(ShipToAddressID) | ||
Types of addresses stored in the Address table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | AddressTypeID | int NOT NULL IDENTITY | Primary key for AddressType records. |
| * | Name | Person.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Address type description. For example, Billing, Home, or Shipping. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_AddressType_AddressTypeID | Primary Key ON AddressTypeID | ||
| AK_AddressType_rowguid | Unique Index ON rowguid | ||
| AK_AddressType_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_BusinessEntityAddress_AddressType_AddressTypeID | AddressTypeID ↙ ❏ Person.BusinessEntityAddress | ||
Source of the ID that connects vendors, customers, and employees with address and contact information.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL IDENTITY | Primary key for all customers, vendors, and employees. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_BusinessEntity_BusinessEntityID | Primary Key ON BusinessEntityID | ||
| AK_BusinessEntity_rowguid | Unique Index ON rowguid | ||
| Referring Foreign Key | |||
| FK_BusinessEntityAddress_BusinessEntity_BusinessEntityID | BusinessEntityID ↙ ❏ Person.BusinessEntityAddress | ||
| FK_BusinessEntityContact_BusinessEntity_BusinessEntityID | BusinessEntityID ↙ ❏ Person.BusinessEntityContact | ||
| FK_Person_BusinessEntity_BusinessEntityID | BusinessEntityID ↙ ❏ Person.Person | ||
| FK_Vendor_BusinessEntity_BusinessEntityID | BusinessEntityID ↙ ❏ Purchasing.Vendor | ||
| FK_Store_BusinessEntity_BusinessEntityID | BusinessEntityID ↙ ❏ Sales.Store | ||
Cross-reference table mapping customers, vendors, and employees to their addresses.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key. Foreign key to BusinessEntity.BusinessEntityID. |
| * | AddressID | int NOT NULL | Primary key. Foreign key to Address.AddressID. |
| * | AddressTypeID | int NOT NULL | Primary key. Foreign key to AddressType.AddressTypeID. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_BusinessEntityAddress_BusinessEntityID_AddressID_AddressTypeID | Primary Key ON BusinessEntityID, AddressID, AddressTypeID | ||
| AK_BusinessEntityAddress_rowguid | Unique Index ON rowguid | ||
| IX_BusinessEntityAddress_AddressID | Index ON AddressID | ||
| IX_BusinessEntityAddress_AddressTypeID | Index ON AddressTypeID | ||
| Foreign Key | |||
| FK_BusinessEntityAddress_Address_AddressID | AddressID ↗ ❏ Person.Address | ||
| FK_BusinessEntityAddress_AddressType_AddressTypeID | AddressTypeID ↗ ❏ Person.AddressType | ||
| FK_BusinessEntityAddress_BusinessEntity_BusinessEntityID | BusinessEntityID ↗ ❏ Person.BusinessEntity | ||
Cross-reference table mapping stores, vendors, and employees to people
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key. Foreign key to BusinessEntity.BusinessEntityID. |
| * | PersonID | int NOT NULL | Primary key. Foreign key to Person.BusinessEntityID. |
| * | ContactTypeID | int NOT NULL | Primary key. Foreign key to ContactType.ContactTypeID. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_BusinessEntityContact_BusinessEntityID_PersonID_ContactTypeID | Primary Key ON BusinessEntityID, PersonID, ContactTypeID | ||
| AK_BusinessEntityContact_rowguid | Unique Index ON rowguid | ||
| IX_BusinessEntityContact_PersonID | Index ON PersonID | ||
| IX_BusinessEntityContact_ContactTypeID | Index ON ContactTypeID | ||
| Foreign Key | |||
| FK_BusinessEntityContact_BusinessEntity_BusinessEntityID | BusinessEntityID ↗ ❏ Person.BusinessEntity | ||
| FK_BusinessEntityContact_ContactType_ContactTypeID | ContactTypeID ↗ ❏ Person.ContactType | ||
| FK_BusinessEntityContact_Person_PersonID | PersonID ↗ ❏ Person.Person(BusinessEntityID) | ||
Lookup table containing the types of business entity contacts.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ContactTypeID | int NOT NULL IDENTITY | Primary key for ContactType records. |
| * | Name | Person.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Contact type description. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ContactType_ContactTypeID | Primary Key ON ContactTypeID | ||
| AK_ContactType_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_BusinessEntityContact_ContactType_ContactTypeID | ContactTypeID ↙ ❏ Person.BusinessEntityContact | ||
Lookup table containing the ISO standard codes for countries and regions.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | CountryRegionCode | nvarchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | ISO standard code for countries and regions. |
| * | Name | Person.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Country or region name. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_CountryRegion_CountryRegionCode | Primary Key ON CountryRegionCode | ||
| AK_CountryRegion_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_StateProvince_CountryRegion_CountryRegionCode | CountryRegionCode ↙ ❏ Person.StateProvince | ||
| FK_CountryRegionCurrency_CountryRegion_CountryRegionCode | CountryRegionCode ↙ ❏ Sales.CountryRegionCurrency | ||
| FK_SalesTerritory_CountryRegion_CountryRegionCode | CountryRegionCode ↙ ❏ Sales.SalesTerritory | ||
Where to send a person email.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key. Person associated with this email address. Foreign key to Person.BusinessEntityID |
| * | EmailAddressID | int NOT NULL IDENTITY | Primary key. ID of this email address. |
| EmailAddress | nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS | E-mail address for the person. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_EmailAddress_BusinessEntityID_EmailAddressID | Primary Key ON BusinessEntityID, EmailAddressID | ||
| IX_EmailAddress_EmailAddress | Index ON EmailAddress | ||
| Foreign Key | |||
| FK_EmailAddress_Person_BusinessEntityID | BusinessEntityID ↗ ❏ Person.Person | ||
One way hashed authentication information
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | |
| * | PasswordHash | varchar(128) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Password for the e-mail account. |
| * | PasswordSalt | varchar(10) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Random value concatenated with the password string before the password is hashed. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Password_BusinessEntityID | Primary Key ON BusinessEntityID | ||
| Foreign Key | |||
| FK_Password_Person_BusinessEntityID | BusinessEntityID ↗ ❏ Person.Person | ||
Human beings involved with AdventureWorks: employees, customer contacts, and vendor contacts.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key for Person records. |
| * | PersonType | nchar(2) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Primary type of person: SC = Store Contact, IN = Individual (retail) customer, SP = Sales person, EM = Employee (non-sales), VC = Vendor contact, GC = General contact |
| * | NameStyle | Person.NameStyle NOT NULL DEFAULT ((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. |
| Title | nvarchar(8) COLLATE SQL_Latin1_General_CP1_CI_AS | A courtesy title. For example, Mr. or Ms. | |
| * | FirstName | Person.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | First name of the person. |
| MiddleName | Person.Name COLLATE SQL_Latin1_General_CP1_CI_AS | Middle name or middle initial of the person. | |
| * | LastName | Person.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Last name of the person. |
| Suffix | nvarchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS | Surname suffix. For example, Sr. or Jr. | |
| * | EmailPromotion | int NOT NULL DEFAULT 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. |
| AdditionalContactInfo | xml | Additional contact information about the person stored in xml format. | |
| Demographics | xml | Personal information such as hobbies, and income collected from online shoppers. Used for sales analysis. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Person_BusinessEntityID | Primary Key ON BusinessEntityID | ||
| AK_Person_rowguid | Unique Index ON rowguid | ||
| IX_Person_LastName_FirstName_MiddleName | Index ON LastName, FirstName, MiddleName | ||
| Foreign Key | |||
| FK_Person_BusinessEntity_BusinessEntityID | BusinessEntityID ↗ ❏ Person.BusinessEntity | ||
| Referring Foreign Key | |||
| FK_Employee_Person_BusinessEntityID | BusinessEntityID ↙ ❏ HumanResources.Employee | ||
| FK_BusinessEntityContact_Person_PersonID | BusinessEntityID ↙ ❏ Person.BusinessEntityContact(PersonID) | ||
| FK_EmailAddress_Person_BusinessEntityID | BusinessEntityID ↙ ❏ Person.EmailAddress | ||
| FK_Password_Person_BusinessEntityID | BusinessEntityID ↙ ❏ Person.Password | ||
| FK_PersonPhone_Person_BusinessEntityID | BusinessEntityID ↙ ❏ Person.PersonPhone | ||
| FK_Customer_Person_PersonID | BusinessEntityID ↙ ❏ Sales.Customer(PersonID) | ||
| FK_PersonCreditCard_Person_BusinessEntityID | BusinessEntityID ↙ ❏ Sales.PersonCreditCard | ||
| Constraints | |||
| CK_Person_EmailPromotion | [EmailPromotion]>=(0) AND [EmailPromotion]<=(2) | ||
| CK_Person_PersonType | [PersonType] IS NULL OR (upper([PersonType])='GC' OR upper([PersonType])='SP' OR upper([PersonType])='EM' OR upper([PersonType])='IN' OR upper([PersonType])='VC' OR upper([PersonType])='SC') | ||
| Triggers | |||
| iuPerson | CREATE TRIGGER [Person].[${nameWithSchemaName}] ON [Person].[Person]
AFTER INSERT, UPDATE NOT FOR REPLICATION AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
IF UPDATE([BusinessEntityID]) OR UPDATE([Demographics])
BEGIN
UPDATE [Person].[Person]
SET [Person].[Person].[Demographics] = N'<IndividualSurvey xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey">
<TotalPurchaseYTD>0.00</TotalPurchaseYTD>
</IndividualSurvey>'
FROM inserted
WHERE [Person].[Person].[BusinessEntityID] = inserted.[BusinessEntityID]
AND inserted.[Demographics] IS NULL;
UPDATE [Person].[Person]
SET [Demographics].modify(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
insert <TotalPurchaseYTD>0.00</TotalPurchaseYTD>
as first
into (/IndividualSurvey)[1]')
FROM inserted
WHERE [Person].[Person].[BusinessEntityID] = inserted.[BusinessEntityID]
AND inserted.[Demographics] IS NOT NULL
AND inserted.[Demographics].exist(N'declare default element namespace
"http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
/IndividualSurvey/TotalPurchaseYTD') <> 1;
END;
END | ||
Telephone number and type of a person.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Business entity identification number. Foreign key to Person.BusinessEntityID. |
| * | PhoneNumber | Person.Phone NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Telephone number identification number. |
| * | PhoneNumberTypeID | int NOT NULL | Kind of phone number. Foreign key to PhoneNumberType.PhoneNumberTypeID. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_PersonPhone_BusinessEntityID_PhoneNumber_PhoneNumberTypeID | Primary Key ON BusinessEntityID, PhoneNumber, PhoneNumberTypeID | ||
| IX_PersonPhone_PhoneNumber | Index ON PhoneNumber | ||
| Foreign Key | |||
| FK_PersonPhone_Person_BusinessEntityID | BusinessEntityID ↗ ❏ Person.Person | ||
| FK_PersonPhone_PhoneNumberType_PhoneNumberTypeID | PhoneNumberTypeID ↗ ❏ Person.PhoneNumberType | ||
Type of phone number of a person.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | PhoneNumberTypeID | int NOT NULL IDENTITY | Primary key for telephone number type records. |
| * | Name | Person.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Name of the telephone number type |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_PhoneNumberType_PhoneNumberTypeID | Primary Key ON PhoneNumberTypeID | ||
| Referring Foreign Key | |||
| FK_PersonPhone_PhoneNumberType_PhoneNumberTypeID | PhoneNumberTypeID ↙ ❏ Person.PersonPhone | ||
State and province lookup table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | StateProvinceID | int NOT NULL IDENTITY | Primary key for StateProvince records. |
| * | StateProvinceCode | nchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | ISO standard state or province code. |
| * | CountryRegionCode | nvarchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | ISO standard country or region code. Foreign key to CountryRegion.CountryRegionCode. |
| * | IsOnlyStateProvinceFlag | Person.Flag NOT NULL DEFAULT ((1)) | 0 = StateProvinceCode exists. 1 = StateProvinceCode unavailable, using CountryRegionCode. |
| * | Name | Person.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | State or province description. |
| * | TerritoryID | int NOT NULL | ID of the territory in which the state or province is located. Foreign key to SalesTerritory.SalesTerritoryID. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_StateProvince_StateProvinceID | Primary Key ON StateProvinceID | ||
| AK_StateProvince_Name | Unique Index ON Name | ||
| AK_StateProvince_StateProvinceCode_CountryRegionCode | Unique Index ON StateProvinceCode, CountryRegionCode | ||
| AK_StateProvince_rowguid | Unique Index ON rowguid | ||
| Foreign Key | |||
| FK_StateProvince_CountryRegion_CountryRegionCode | CountryRegionCode ↗ ❏ Person.CountryRegion | ||
| FK_StateProvince_SalesTerritory_TerritoryID | TerritoryID ↗ ❏ Sales.SalesTerritory | ||
| Referring Foreign Key | |||
| FK_Address_StateProvince_StateProvinceID | StateProvinceID ↙ ❏ Person.Address | ||
| FK_SalesTaxRate_StateProvince_StateProvinceID | StateProvinceID ↙ ❏ Sales.SalesTaxRate | ||
Items required to make bicycles and bicycle subassemblies. It identifies the heirarchical relationship between a parent product and its components.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BillOfMaterialsID | int NOT NULL IDENTITY | Primary key for BillOfMaterials records. |
| ProductAssemblyID | int | Parent product identification number. Foreign key to Product.ProductID. | |
| * | ComponentID | int NOT NULL | Component identification number. Foreign key to Product.ProductID. |
| * | StartDate | datetime NOT NULL DEFAULT getdate() | Date the component started being used in the assembly item. |
| EndDate | datetime | Date the component stopped being used in the assembly item. | |
| * | UnitMeasureCode | nchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Standard code identifying the unit of measure for the quantity. |
| * | BOMLevel | smallint NOT NULL | Indicates the depth the component is from its parent (AssemblyID). |
| * | PerAssemblyQty | decimal(8,2) NOT NULL DEFAULT 1.00 | Quantity of the component needed to create the assembly. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_BillOfMaterials_BillOfMaterialsID | Primary Key ON BillOfMaterialsID | ||
| AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate | Unique Index ON ProductAssemblyID, ComponentID, StartDate | ||
| IX_BillOfMaterials_UnitMeasureCode | Index ON UnitMeasureCode | ||
| Foreign Key | |||
| FK_BillOfMaterials_Product_ComponentID | ComponentID ↗ ❏ Production.Product(ProductID) | ||
| FK_BillOfMaterials_Product_ProductAssemblyID | ProductAssemblyID ↗ ❏ Production.Product(ProductID) | ||
| FK_BillOfMaterials_UnitMeasure_UnitMeasureCode | UnitMeasureCode ↗ ❏ Production.UnitMeasure | ||
| Constraints | |||
| CK_BillOfMaterials_EndDate | [EndDate]>[StartDate] OR [EndDate] IS NULL | ||
| CK_BillOfMaterials_ProductAssemblyID | [ProductAssemblyID]<>[ComponentID] | ||
| CK_BillOfMaterials_BOMLevel | [ProductAssemblyID] IS NULL AND [BOMLevel]=(0) AND [PerAssemblyQty]=(1.00) OR [ProductAssemblyID] IS NOT NULL AND [BOMLevel]>=(1) | ||
| CK_BillOfMaterials_PerAssemblyQty | [PerAssemblyQty]>=(1.00) | ||
Lookup table containing the languages in which some AdventureWorks data is stored.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | CultureID | nchar(6) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Primary key for Culture records. |
| * | Name | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Culture description. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Culture_CultureID | Primary Key ON CultureID | ||
| AK_Culture_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_ProductModelProductDescriptionCulture_Culture_CultureID | CultureID ↙ ❏ Production.ProductModelProductDescriptionCulture | ||
Product maintenance documents.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | DocumentNode | hierarchyid NOT NULL | Primary key for Document records. |
| DocumentLevel | text | Depth in the document hierarchy. | |
| * | Title | nvarchar(50) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Title of the document. |
| * | Owner | int NOT NULL | Employee who controls the document. Foreign key to Employee.BusinessEntityID |
| * | FolderFlag | bit NOT NULL DEFAULT 0 | 0 = This is a folder, 1 = This is a document. |
| * | FileName | nvarchar(400) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | File name of the document |
| * | FileExtension | nvarchar(8) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | File extension indicating the document type. For example, .doc or .txt. |
| * | Revision | nchar(5) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Revision number of the document. |
| * | ChangeNumber | int NOT NULL DEFAULT 0 | Engineering change approval number. |
| * | Status | tinyint NOT NULL | 1 = Pending approval, 2 = Approved, 3 = Obsolete |
| DocumentSummary | nvarchar(max) COLLATE SQL_Latin1_General_CP1_CI_AS | Document abstract. | |
| Document | varbinary(max) | Complete document. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Required for FileStream. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Document_DocumentNode | Primary Key ON DocumentNode | ||
| AK_Document_DocumentLevel_DocumentNode | Unique Index ON DocumentLevel, DocumentNode | ||
| AK_Document_rowguid | Unique Index ON rowguid | ||
| IX_Document_FileName_Revision | Index ON FileName, Revision | ||
| Foreign Key | |||
| FK_Document_Employee_Owner | Owner ↗ ❏ HumanResources.Employee(BusinessEntityID) | ||
| Referring Foreign Key | |||
| FK_ProductDocument_Document_DocumentNode | DocumentNode ↙ ❏ Production.ProductDocument | ||
| Constraints | |||
| CK_Document_Status | [Status]>=(1) AND [Status]<=(3) | ||
Bicycle assembly diagrams.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | IllustrationID | int NOT NULL IDENTITY | Primary key for Illustration records. |
| Diagram | xml | Illustrations used in manufacturing instructions. Stored as XML. | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Illustration_IllustrationID | Primary Key ON IllustrationID | ||
| Referring Foreign Key | |||
| FK_ProductModelIllustration_Illustration_IllustrationID | IllustrationID ↙ ❏ Production.ProductModelIllustration | ||
Product inventory and manufacturing locations.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | LocationID | smallint NOT NULL IDENTITY | Primary key for Location records. |
| * | Name | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Location description. |
| * | CostRate | smallmoney NOT NULL DEFAULT 0.00 | Standard hourly cost of the manufacturing location. |
| * | Availability | decimal(8,2) NOT NULL DEFAULT 0.00 | Work capacity (in hours) of the manufacturing location. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Location_LocationID | Primary Key ON LocationID | ||
| AK_Location_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_ProductInventory_Location_LocationID | LocationID ↙ ❏ Production.ProductInventory | ||
| FK_WorkOrderRouting_Location_LocationID | LocationID ↙ ❏ Production.WorkOrderRouting | ||
| Constraints | |||
| CK_Location_CostRate | [CostRate]>=(0.00) | ||
| CK_Location_Availability | [Availability]>=(0.00) | ||
Products sold or used in the manfacturing of sold products.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductID | int NOT NULL IDENTITY | Primary key for Product records. |
| * | Name | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Name of the product. |
| * | ProductNumber | nvarchar(25) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Unique product identification number. |
| * | MakeFlag | Production.Flag NOT NULL DEFAULT ((1)) | 0 = Product is purchased, 1 = Product is manufactured in-house. |
| * | FinishedGoodsFlag | Production.Flag NOT NULL DEFAULT ((1)) | 0 = Product is not a salable item. 1 = Product is salable. |
| Color | nvarchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS | Product color. | |
| * | SafetyStockLevel | smallint NOT NULL | Minimum inventory quantity. |
| * | ReorderPoint | smallint NOT NULL | Inventory level that triggers a purchase order or work order. |
| * | StandardCost | money NOT NULL | Standard cost of the product. |
| * | ListPrice | money NOT NULL | Selling price. |
| Size | nvarchar(5) COLLATE SQL_Latin1_General_CP1_CI_AS | Product size. | |
| SizeUnitMeasureCode | nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS | Unit of measure for Size column. | |
| WeightUnitMeasureCode | nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS | Unit of measure for Weight column. | |
| Weight | decimal(8,2) | Product weight. | |
| * | DaysToManufacture | int NOT NULL | Number of days required to manufacture the product. |
| ProductLine | nchar(2) COLLATE SQL_Latin1_General_CP1_CI_AS | R = Road, M = Mountain, T = Touring, S = Standard | |
| Class | nchar(2) COLLATE SQL_Latin1_General_CP1_CI_AS | H = High, M = Medium, L = Low | |
| Style | nchar(2) COLLATE SQL_Latin1_General_CP1_CI_AS | W = Womens, M = Mens, U = Universal | |
| ProductSubcategoryID | int | Product is a member of this product subcategory. Foreign key to ProductSubCategory.ProductSubCategoryID. | |
| ProductModelID | int | Product is a member of this product model. Foreign key to ProductModel.ProductModelID. | |
| * | SellStartDate | datetime NOT NULL | Date the product was available for sale. |
| SellEndDate | datetime | Date the product was no longer available for sale. | |
| DiscontinuedDate | datetime | Date the product was discontinued. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Product_ProductID | Primary Key ON ProductID | ||
| AK_Product_ProductNumber | Unique Index ON ProductNumber | ||
| AK_Product_Name | Unique Index ON Name | ||
| AK_Product_rowguid | Unique Index ON rowguid | ||
| Foreign Key | |||
| FK_Product_ProductModel_ProductModelID | ProductModelID ↗ ❏ Production.ProductModel | ||
| FK_Product_ProductSubcategory_ProductSubcategoryID | ProductSubcategoryID ↗ ❏ Production.ProductSubcategory | ||
| FK_Product_UnitMeasure_SizeUnitMeasureCode | SizeUnitMeasureCode ↗ ❏ Production.UnitMeasure(UnitMeasureCode) | ||
| FK_Product_UnitMeasure_WeightUnitMeasureCode | WeightUnitMeasureCode ↗ ❏ Production.UnitMeasure(UnitMeasureCode) | ||
| Referring Foreign Key | |||
| FK_BillOfMaterials_Product_ComponentID | ProductID ↙ ❏ Production.BillOfMaterials(ComponentID) | ||
| FK_BillOfMaterials_Product_ProductAssemblyID | ProductID ↙ ❏ Production.BillOfMaterials(ProductAssemblyID) | ||
| FK_ProductCostHistory_Product_ProductID | ProductID ↙ ❏ Production.ProductCostHistory | ||
| FK_ProductDocument_Product_ProductID | ProductID ↙ ❏ Production.ProductDocument | ||
| FK_ProductInventory_Product_ProductID | ProductID ↙ ❏ Production.ProductInventory | ||
| FK_ProductListPriceHistory_Product_ProductID | ProductID ↙ ❏ Production.ProductListPriceHistory | ||
| FK_ProductProductPhoto_Product_ProductID | ProductID ↙ ❏ Production.ProductProductPhoto | ||
| FK_ProductReview_Product_ProductID | ProductID ↙ ❏ Production.ProductReview | ||
| FK_TransactionHistory_Product_ProductID | ProductID ↙ ❏ Production.TransactionHistory | ||
| FK_WorkOrder_Product_ProductID | ProductID ↙ ❏ Production.WorkOrder | ||
| FK_ProductVendor_Product_ProductID | ProductID ↙ ❏ Purchasing.ProductVendor | ||
| FK_PurchaseOrderDetail_Product_ProductID | ProductID ↙ ❏ Purchasing.PurchaseOrderDetail | ||
| FK_ShoppingCartItem_Product_ProductID | ProductID ↙ ❏ Sales.ShoppingCartItem | ||
| FK_SpecialOfferProduct_Product_ProductID | ProductID ↙ ❏ Sales.SpecialOfferProduct | ||
| Constraints | |||
| CK_Product_SafetyStockLevel | [SafetyStockLevel]>(0) | ||
| CK_Product_ReorderPoint | [ReorderPoint]>(0) | ||
| CK_Product_StandardCost | [StandardCost]>=(0.00) | ||
| CK_Product_ListPrice | [ListPrice]>=(0.00) | ||
| CK_Product_Weight | [Weight]>(0.00) | ||
| CK_Product_DaysToManufacture | [DaysToManufacture]>=(0) | ||
| CK_Product_ProductLine | upper([ProductLine])='R' OR upper([ProductLine])='M' OR upper([ProductLine])='T' OR upper([ProductLine])='S' OR [ProductLine] IS NULL | ||
| CK_Product_Class | upper([Class])='H' OR upper([Class])='M' OR upper([Class])='L' OR [Class] IS NULL | ||
| CK_Product_Style | upper([Style])='U' OR upper([Style])='M' OR upper([Style])='W' OR [Style] IS NULL | ||
| CK_Product_SellEndDate | [SellEndDate]>=[SellStartDate] OR [SellEndDate] IS NULL | ||
High-level product categorization.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductCategoryID | int NOT NULL IDENTITY | Primary key for ProductCategory records. |
| * | Name | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Category description. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductCategory_ProductCategoryID | Primary Key ON ProductCategoryID | ||
| AK_ProductCategory_Name | Unique Index ON Name | ||
| AK_ProductCategory_rowguid | Unique Index ON rowguid | ||
| Referring Foreign Key | |||
| FK_ProductSubcategory_ProductCategory_ProductCategoryID | ProductCategoryID ↙ ❏ Production.ProductSubcategory | ||
Changes in the cost of a product over time.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID |
| * | StartDate | datetime NOT NULL | Product cost start date. |
| EndDate | datetime | Product cost end date. | |
| * | StandardCost | money NOT NULL | Standard cost of the product. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductCostHistory_ProductID_StartDate | Primary Key ON ProductID, StartDate | ||
| Foreign Key | |||
| FK_ProductCostHistory_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| Constraints | |||
| CK_ProductCostHistory_EndDate | [EndDate]>=[StartDate] OR [EndDate] IS NULL | ||
| CK_ProductCostHistory_StandardCost | [StandardCost]>=(0.00) | ||
Product descriptions in several languages.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductDescriptionID | int NOT NULL IDENTITY | Primary key for ProductDescription records. |
| * | Description | nvarchar(400) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Description of the product. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductDescription_ProductDescriptionID | Primary Key ON ProductDescriptionID | ||
| AK_ProductDescription_rowguid | Unique Index ON rowguid | ||
| Referring Foreign Key | |||
| FK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionID | ProductDescriptionID ↙ ❏ Production.ProductModelProductDescriptionCulture | ||
Cross-reference table mapping products to related product documents.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID. |
| * | DocumentNode | hierarchyid NOT NULL | Document identification number. Foreign key to Document.DocumentNode. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductDocument_ProductID_DocumentNode | Primary Key ON ProductID, DocumentNode | ||
| Foreign Key | |||
| FK_ProductDocument_Document_DocumentNode | DocumentNode ↗ ❏ Production.Document | ||
| FK_ProductDocument_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
Product inventory information.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID. |
| * | LocationID | smallint NOT NULL | Inventory location identification number. Foreign key to Location.LocationID. |
| * | Shelf | nvarchar(10) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Storage compartment within an inventory location. |
| * | Bin | tinyint NOT NULL | Storage container on a shelf in an inventory location. |
| * | Quantity | smallint NOT NULL DEFAULT 0 | Quantity of products in the inventory location. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductInventory_ProductID_LocationID | Primary Key ON ProductID, LocationID | ||
| Foreign Key | |||
| FK_ProductInventory_Location_LocationID | LocationID ↗ ❏ Production.Location | ||
| FK_ProductInventory_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| Constraints | |||
| CK_ProductInventory_Shelf | [Shelf] like '[A-Za-z]' OR [Shelf]='N/A' | ||
| CK_ProductInventory_Bin | [Bin]>=(0) AND [Bin]<=(100) | ||
Changes in the list price of a product over time.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID |
| * | StartDate | datetime NOT NULL | List price start date. |
| EndDate | datetime | List price end date | |
| * | ListPrice | money NOT NULL | Product list price. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductListPriceHistory_ProductID_StartDate | Primary Key ON ProductID, StartDate | ||
| Foreign Key | |||
| FK_ProductListPriceHistory_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| Constraints | |||
| CK_ProductListPriceHistory_EndDate | [EndDate]>=[StartDate] OR [EndDate] IS NULL | ||
| CK_ProductListPriceHistory_ListPrice | [ListPrice]>(0.00) | ||
Product model classification.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductModelID | int NOT NULL IDENTITY | Primary key for ProductModel records. |
| * | Name | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Product model description. |
| CatalogDescription | xml | Detailed product catalog information in xml format. | |
| Instructions | xml | Manufacturing instructions in xml format. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductModel_ProductModelID | Primary Key ON ProductModelID | ||
| AK_ProductModel_Name | Unique Index ON Name | ||
| AK_ProductModel_rowguid | Unique Index ON rowguid | ||
| Referring Foreign Key | |||
| FK_Product_ProductModel_ProductModelID | ProductModelID ↙ ❏ Production.Product | ||
| FK_ProductModelIllustration_ProductModel_ProductModelID | ProductModelID ↙ ❏ Production.ProductModelIllustration | ||
| FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID | ProductModelID ↙ ❏ Production.ProductModelProductDescriptionCulture | ||
Cross-reference table mapping product models and illustrations.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductModelID | int NOT NULL | Primary key. Foreign key to ProductModel.ProductModelID. |
| * | IllustrationID | int NOT NULL | Primary key. Foreign key to Illustration.IllustrationID. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductModelIllustration_ProductModelID_IllustrationID | Primary Key ON ProductModelID, IllustrationID | ||
| Foreign Key | |||
| FK_ProductModelIllustration_Illustration_IllustrationID | IllustrationID ↗ ❏ Production.Illustration | ||
| FK_ProductModelIllustration_ProductModel_ProductModelID | ProductModelID ↗ ❏ Production.ProductModel | ||
Cross-reference table mapping product descriptions and the language the description is written in.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductModelID | int NOT NULL | Primary key. Foreign key to ProductModel.ProductModelID. |
| * | ProductDescriptionID | int NOT NULL | Primary key. Foreign key to ProductDescription.ProductDescriptionID. |
| * | CultureID | nchar(6) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Culture identification number. Foreign key to Culture.CultureID. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductModelProductDescriptionCulture_ProductModelID_ProductDescriptionID_CultureID | Primary Key ON ProductModelID, ProductDescriptionID, CultureID | ||
| Foreign Key | |||
| FK_ProductModelProductDescriptionCulture_Culture_CultureID | CultureID ↗ ❏ Production.Culture | ||
| FK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionID | ProductDescriptionID ↗ ❏ Production.ProductDescription | ||
| FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID | ProductModelID ↗ ❏ Production.ProductModel | ||
Product images.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductPhotoID | int NOT NULL IDENTITY | Primary key for ProductPhoto records. |
| ThumbNailPhoto | varbinary(max) | Small image of the product. | |
| ThumbnailPhotoFileName | nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS | Small image file name. | |
| LargePhoto | varbinary(max) | Large image of the product. | |
| LargePhotoFileName | nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS | Large image file name. | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductPhoto_ProductPhotoID | Primary Key ON ProductPhotoID | ||
| Referring Foreign Key | |||
| FK_ProductProductPhoto_ProductPhoto_ProductPhotoID | ProductPhotoID ↙ ❏ Production.ProductProductPhoto | ||
Cross-reference table mapping products and product photos.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID. |
| * | ProductPhotoID | int NOT NULL | Product photo identification number. Foreign key to ProductPhoto.ProductPhotoID. |
| * | Primary | Production.Flag NOT NULL DEFAULT ((0)) | 0 = Photo is not the principal image. 1 = Photo is the principal image. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductProductPhoto_ProductID_ProductPhotoID | Primary Key ON ProductID, ProductPhotoID | ||
| Foreign Key | |||
| FK_ProductProductPhoto_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| FK_ProductProductPhoto_ProductPhoto_ProductPhotoID | ProductPhotoID ↗ ❏ Production.ProductPhoto | ||
Customer reviews of products they have purchased.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductReviewID | int NOT NULL IDENTITY | Primary key for ProductReview records. |
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID. |
| * | ReviewerName | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Name of the reviewer. |
| * | ReviewDate | datetime NOT NULL DEFAULT getdate() | Date review was submitted. |
| * | EmailAddress | nvarchar(50) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Reviewer's e-mail address. |
| * | Rating | int NOT NULL | Product rating given by the reviewer. Scale is 1 to 5 with 5 as the highest rating. |
| Comments | nvarchar(3850) COLLATE SQL_Latin1_General_CP1_CI_AS | Reviewer's comments | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductReview_ProductReviewID | Primary Key ON ProductReviewID | ||
| IX_ProductReview_ProductID_Name | Index ON ProductID, ReviewerName | ||
| Foreign Key | |||
| FK_ProductReview_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| Constraints | |||
| CK_ProductReview_Rating | [Rating]>=(1) AND [Rating]<=(5) | ||
Product subcategories. See ProductCategory table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductSubcategoryID | int NOT NULL IDENTITY | Primary key for ProductSubcategory records. |
| * | ProductCategoryID | int NOT NULL | Product category identification number. Foreign key to ProductCategory.ProductCategoryID. |
| * | Name | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Subcategory description. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductSubcategory_ProductSubcategoryID | Primary Key ON ProductSubcategoryID | ||
| AK_ProductSubcategory_Name | Unique Index ON Name | ||
| AK_ProductSubcategory_rowguid | Unique Index ON rowguid | ||
| Foreign Key | |||
| FK_ProductSubcategory_ProductCategory_ProductCategoryID | ProductCategoryID ↗ ❏ Production.ProductCategory | ||
| Referring Foreign Key | |||
| FK_Product_ProductSubcategory_ProductSubcategoryID | ProductSubcategoryID ↙ ❏ Production.Product | ||
Manufacturing failure reasons lookup table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ScrapReasonID | smallint NOT NULL IDENTITY | Primary key for ScrapReason records. |
| * | Name | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Failure description. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ScrapReason_ScrapReasonID | Primary Key ON ScrapReasonID | ||
| AK_ScrapReason_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_WorkOrder_ScrapReason_ScrapReasonID | ScrapReasonID ↙ ❏ Production.WorkOrder | ||
Record of each purchase order, sales order, or work order transaction year to date.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | TransactionID | int NOT NULL IDENTITY | Primary key for TransactionHistory records. |
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID. |
| * | ReferenceOrderID | int NOT NULL | Purchase order, sales order, or work order identification number. |
| * | ReferenceOrderLineID | int NOT NULL DEFAULT 0 | Line number associated with the purchase order, sales order, or work order. |
| * | TransactionDate | datetime NOT NULL DEFAULT getdate() | Date and time of the transaction. |
| * | TransactionType | nchar(1) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | W = WorkOrder, S = SalesOrder, P = PurchaseOrder |
| * | Quantity | int NOT NULL | Product quantity. |
| * | ActualCost | money NOT NULL | Product cost. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_TransactionHistory_TransactionID | Primary Key ON TransactionID | ||
| IX_TransactionHistory_ProductID | Index ON ProductID | ||
| IX_TransactionHistory_ReferenceOrderID_ReferenceOrderLineID | Index ON ReferenceOrderID, ReferenceOrderLineID | ||
| Foreign Key | |||
| FK_TransactionHistory_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| Constraints | |||
| CK_TransactionHistory_TransactionType | upper([TransactionType])='P' OR upper([TransactionType])='S' OR upper([TransactionType])='W' | ||
Transactions for previous years.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | TransactionID | int NOT NULL | Primary key for TransactionHistoryArchive records. |
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID. |
| * | ReferenceOrderID | int NOT NULL | Purchase order, sales order, or work order identification number. |
| * | ReferenceOrderLineID | int NOT NULL DEFAULT 0 | Line number associated with the purchase order, sales order, or work order. |
| * | TransactionDate | datetime NOT NULL DEFAULT getdate() | Date and time of the transaction. |
| * | TransactionType | nchar(1) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | W = Work Order, S = Sales Order, P = Purchase Order |
| * | Quantity | int NOT NULL | Product quantity. |
| * | ActualCost | money NOT NULL | Product cost. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_TransactionHistoryArchive_TransactionID | Primary Key ON TransactionID | ||
| IX_TransactionHistoryArchive_ProductID | Index ON ProductID | ||
| IX_TransactionHistoryArchive_ReferenceOrderID_ReferenceOrderLineID | Index ON ReferenceOrderID, ReferenceOrderLineID | ||
| Constraints | |||
| CK_TransactionHistoryArchive_TransactionType | upper([TransactionType])='P' OR upper([TransactionType])='S' OR upper([TransactionType])='W' | ||
Unit of measure lookup table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | UnitMeasureCode | nchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Primary key. |
| * | Name | Production.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Unit of measure description. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_UnitMeasure_UnitMeasureCode | Primary Key ON UnitMeasureCode | ||
| AK_UnitMeasure_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_BillOfMaterials_UnitMeasure_UnitMeasureCode | UnitMeasureCode ↙ ❏ Production.BillOfMaterials | ||
| FK_Product_UnitMeasure_SizeUnitMeasureCode | UnitMeasureCode ↙ ❏ Production.Product(SizeUnitMeasureCode) | ||
| FK_Product_UnitMeasure_WeightUnitMeasureCode | UnitMeasureCode ↙ ❏ Production.Product(WeightUnitMeasureCode) | ||
| FK_ProductVendor_UnitMeasure_UnitMeasureCode | UnitMeasureCode ↙ ❏ Purchasing.ProductVendor | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | WorkOrderID | int NOT NULL IDENTITY |
| * | ProductID | int NOT NULL |
| * | OrderQty | int NOT NULL |
| StockedQty | text | |
| * | ScrappedQty | smallint NOT NULL |
| * | StartDate | datetime NOT NULL |
| EndDate | datetime | |
| * | DueDate | datetime NOT NULL |
| ScrapReasonID | smallint | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() |
| Indexes | ||
| PK_WorkOrder_WorkOrderID | Primary Key ON WorkOrderID | |
| IX_WorkOrder_ScrapReasonID | Index ON ScrapReasonID | |
| IX_WorkOrder_ProductID | Index ON ProductID | |
| Foreign Key | ||
| FK_WorkOrder_Product_ProductID | ProductID ↗ ❏ Production.Product | |
| FK_WorkOrder_ScrapReason_ScrapReasonID | ScrapReasonID ↗ ❏ Production.ScrapReason | |
| Referring Foreign Key | ||
| FK_WorkOrderRouting_WorkOrder_WorkOrderID | WorkOrderID ↙ ❏ Production.WorkOrderRouting | |
| Constraints | ||
| CK_WorkOrder_OrderQty | [OrderQty]>(0) | |
| CK_WorkOrder_ScrappedQty | [ScrappedQty]>=(0) | |
| CK_WorkOrder_EndDate | [EndDate]>=[StartDate] OR [EndDate] IS NULL | |
| Triggers | ||
| iWorkOrder | CREATE TRIGGER [Production].[${nameWithSchemaName}] ON [Production].[WorkOrder]
AFTER INSERT AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
INSERT INTO [Production].[TransactionHistory](
[ProductID]
,[ReferenceOrderID]
,[TransactionType]
,[TransactionDate]
,[Quantity]
,[ActualCost])
SELECT
inserted.[ProductID]
,inserted.[WorkOrderID]
,'W'
,GETDATE()
,inserted.[OrderQty]
,0
FROM inserted;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END | |
| uWorkOrder | CREATE TRIGGER [Production].[${nameWithSchemaName}] ON [Production].[WorkOrder]
AFTER UPDATE AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
IF UPDATE([ProductID]) OR UPDATE([OrderQty])
BEGIN
INSERT INTO [Production].[TransactionHistory](
[ProductID]
,[ReferenceOrderID]
,[TransactionType]
,[TransactionDate]
,[Quantity])
SELECT
inserted.[ProductID]
,inserted.[WorkOrderID]
,'W'
,GETDATE()
,inserted.[OrderQty]
FROM inserted;
END;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END | |
| Idx | Column Name | Data Type |
|---|---|---|
| * | WorkOrderID | int NOT NULL |
| * | ProductID | int NOT NULL |
| * | OperationSequence | smallint NOT NULL |
| * | LocationID | smallint NOT NULL |
| * | ScheduledStartDate | datetime NOT NULL |
| * | ScheduledEndDate | datetime NOT NULL |
| ActualStartDate | datetime | |
| ActualEndDate | datetime | |
| ActualResourceHrs | decimal(9,4) | |
| * | PlannedCost | money NOT NULL |
| ActualCost | money | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() |
| Indexes | ||
| PK_WorkOrderRouting_WorkOrderID_ProductID_OperationSequence | Primary Key ON WorkOrderID, ProductID, OperationSequence | |
| IX_WorkOrderRouting_ProductID | Index ON ProductID | |
| Foreign Key | ||
| FK_WorkOrderRouting_Location_LocationID | LocationID ↗ ❏ Production.Location | |
| FK_WorkOrderRouting_WorkOrder_WorkOrderID | WorkOrderID ↗ ❏ Production.WorkOrder | |
| Constraints | ||
| CK_WorkOrderRouting_ScheduledEndDate | [ScheduledEndDate]>=[ScheduledStartDate] | |
| CK_WorkOrderRouting_ActualEndDate | [ActualEndDate]>=[ActualStartDate] OR [ActualEndDate] IS NULL OR [ActualStartDate] IS NULL | |
| CK_WorkOrderRouting_ActualResourceHrs | [ActualResourceHrs]>=(0.0000) | |
| CK_WorkOrderRouting_PlannedCost | [PlannedCost]>(0.00) | |
| CK_WorkOrderRouting_ActualCost | [ActualCost]>(0.00) | |
Cross-reference table mapping vendors with the products they supply.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ProductID | int NOT NULL | Primary key. Foreign key to Product.ProductID. |
| * | BusinessEntityID | int NOT NULL | Primary key. Foreign key to Vendor.BusinessEntityID. |
| * | AverageLeadTime | int NOT NULL | The average span of time (in days) between placing an order with the vendor and receiving the purchased product. |
| * | StandardPrice | money NOT NULL | The vendor's usual selling price. |
| LastReceiptCost | money | The selling price when last purchased. | |
| LastReceiptDate | datetime | Date the product was last received by the vendor. | |
| * | MinOrderQty | int NOT NULL | The maximum quantity that should be ordered. |
| * | MaxOrderQty | int NOT NULL | The minimum quantity that should be ordered. |
| OnOrderQty | int | The quantity currently on order. | |
| * | UnitMeasureCode | nchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | The product's unit of measure. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ProductVendor_ProductID_BusinessEntityID | Primary Key ON ProductID, BusinessEntityID | ||
| IX_ProductVendor_UnitMeasureCode | Index ON UnitMeasureCode | ||
| IX_ProductVendor_BusinessEntityID | Index ON BusinessEntityID | ||
| Foreign Key | |||
| FK_ProductVendor_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| FK_ProductVendor_UnitMeasure_UnitMeasureCode | UnitMeasureCode ↗ ❏ Production.UnitMeasure | ||
| FK_ProductVendor_Vendor_BusinessEntityID | BusinessEntityID ↗ ❏ Purchasing.Vendor | ||
| Constraints | |||
| CK_ProductVendor_AverageLeadTime | [AverageLeadTime]>=(1) | ||
| CK_ProductVendor_StandardPrice | [StandardPrice]>(0.00) | ||
| CK_ProductVendor_LastReceiptCost | [LastReceiptCost]>(0.00) | ||
| CK_ProductVendor_MinOrderQty | [MinOrderQty]>=(1) | ||
| CK_ProductVendor_MaxOrderQty | [MaxOrderQty]>=(1) | ||
| CK_ProductVendor_OnOrderQty | [OnOrderQty]>=(0) | ||
Individual products associated with a specific purchase order. See PurchaseOrderHeader.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | PurchaseOrderID | int NOT NULL | Primary key. Foreign key to PurchaseOrderHeader.PurchaseOrderID. |
| * | PurchaseOrderDetailID | int NOT NULL IDENTITY | Primary key. One line number per purchased product. |
| * | DueDate | datetime NOT NULL | Date the product is expected to be received. |
| * | OrderQty | smallint NOT NULL | Quantity ordered. |
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID. |
| * | UnitPrice | money NOT NULL | Vendor's selling price of a single product. |
| LineTotal | text | Per product subtotal. Computed as OrderQty * UnitPrice. | |
| * | ReceivedQty | decimal(8,2) NOT NULL | Quantity actually received from the vendor. |
| * | RejectedQty | decimal(8,2) NOT NULL | Quantity rejected during inspection. |
| StockedQty | text | Quantity accepted into inventory. Computed as ReceivedQty - RejectedQty. | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_PurchaseOrderDetail_PurchaseOrderID_PurchaseOrderDetailID | Primary Key ON PurchaseOrderID, PurchaseOrderDetailID | ||
| IX_PurchaseOrderDetail_ProductID | Index ON ProductID | ||
| Foreign Key | |||
| FK_PurchaseOrderDetail_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| FK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderID | PurchaseOrderID ↗ ❏ Purchasing.PurchaseOrderHeader | ||
| Constraints | |||
| CK_PurchaseOrderDetail_OrderQty | [OrderQty]>(0) | ||
| CK_PurchaseOrderDetail_UnitPrice | [UnitPrice]>=(0.00) | ||
| CK_PurchaseOrderDetail_ReceivedQty | [ReceivedQty]>=(0.00) | ||
| CK_PurchaseOrderDetail_RejectedQty | [RejectedQty]>=(0.00) | ||
| Triggers | |||
| iPurchaseOrderDetail | CREATE TRIGGER [Purchasing].[${nameWithSchemaName}] ON [Purchasing].[PurchaseOrderDetail]
AFTER INSERT AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
INSERT INTO [Production].[TransactionHistory]
([ProductID]
,[ReferenceOrderID]
,[ReferenceOrderLineID]
,[TransactionType]
,[TransactionDate]
,[Quantity]
,[ActualCost])
SELECT
inserted.[ProductID]
,inserted.[PurchaseOrderID]
,inserted.[PurchaseOrderDetailID]
,'P'
,GETDATE()
,inserted.[OrderQty]
,inserted.[UnitPrice]
FROM inserted
INNER JOIN [Purchasing].[PurchaseOrderHeader]
ON inserted.[PurchaseOrderID] = [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID];
-- Update SubTotal in PurchaseOrderHeader record. Note that this causes the
-- PurchaseOrderHeader trigger to fire which will update the RevisionNumber.
UPDATE [Purchasing].[PurchaseOrderHeader]
SET [Purchasing].[PurchaseOrderHeader].[SubTotal] =
(SELECT SUM([Purchasing].[PurchaseOrderDetail].[LineTotal])
FROM [Purchasing].[PurchaseOrderDetail]
WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderID])
WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] IN (SELECT inserted.[PurchaseOrderID] FROM inserted);
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END | ||
| uPurchaseOrderDetail | CREATE TRIGGER [Purchasing].[${nameWithSchemaName}] ON [Purchasing].[PurchaseOrderDetail]
AFTER UPDATE AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
IF UPDATE([ProductID]) OR UPDATE([OrderQty]) OR UPDATE([UnitPrice])
-- Insert record into TransactionHistory
BEGIN
INSERT INTO [Production].[TransactionHistory]
([ProductID]
,[ReferenceOrderID]
,[ReferenceOrderLineID]
,[TransactionType]
,[TransactionDate]
,[Quantity]
,[ActualCost])
SELECT
inserted.[ProductID]
,inserted.[PurchaseOrderID]
,inserted.[PurchaseOrderDetailID]
,'P'
,GETDATE()
,inserted.[OrderQty]
,inserted.[UnitPrice]
FROM inserted
INNER JOIN [Purchasing].[PurchaseOrderDetail]
ON inserted.[PurchaseOrderID] = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderID];
-- Update SubTotal in PurchaseOrderHeader record. Note that this causes the
-- PurchaseOrderHeader trigger to fire which will update the RevisionNumber.
UPDATE [Purchasing].[PurchaseOrderHeader]
SET [Purchasing].[PurchaseOrderHeader].[SubTotal] =
(SELECT SUM([Purchasing].[PurchaseOrderDetail].[LineTotal])
FROM [Purchasing].[PurchaseOrderDetail]
WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID]
= [Purchasing].[PurchaseOrderDetail].[PurchaseOrderID])
WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID]
IN (SELECT inserted.[PurchaseOrderID] FROM inserted);
UPDATE [Purchasing].[PurchaseOrderDetail]
SET [Purchasing].[PurchaseOrderDetail].[ModifiedDate] = GETDATE()
FROM inserted
WHERE inserted.[PurchaseOrderID] = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderID]
AND inserted.[PurchaseOrderDetailID] = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderDetailID];
END;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END | ||
General purchase order information. See PurchaseOrderDetail.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | PurchaseOrderID | int NOT NULL IDENTITY | Primary key. |
| * | RevisionNumber | tinyint NOT NULL DEFAULT 0 | Incremental number to track changes to the purchase order over time. |
| * | Status | tinyint NOT NULL DEFAULT 1 | Order current status. 1 = Pending; 2 = Approved; 3 = Rejected; 4 = Complete |
| * | EmployeeID | int NOT NULL | Employee who created the purchase order. Foreign key to Employee.BusinessEntityID. |
| * | VendorID | int NOT NULL | Vendor with whom the purchase order is placed. Foreign key to Vendor.BusinessEntityID. |
| * | ShipMethodID | int NOT NULL | Shipping method. Foreign key to ShipMethod.ShipMethodID. |
| * | OrderDate | datetime NOT NULL DEFAULT getdate() | Purchase order creation date. |
| ShipDate | datetime | Estimated shipment date from the vendor. | |
| * | SubTotal | money NOT NULL DEFAULT 0.00 | Purchase order subtotal. Computed as SUM(PurchaseOrderDetail.LineTotal)for the appropriate PurchaseOrderID. |
| * | TaxAmt | money NOT NULL DEFAULT 0.00 | Tax amount. |
| * | Freight | money NOT NULL DEFAULT 0.00 | Shipping cost. |
| TotalDue | text | Total due to vendor. Computed as Subtotal + TaxAmt + Freight. | |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_PurchaseOrderHeader_PurchaseOrderID | Primary Key ON PurchaseOrderID | ||
| IX_PurchaseOrderHeader_VendorID | Index ON VendorID | ||
| IX_PurchaseOrderHeader_EmployeeID | Index ON EmployeeID | ||
| Foreign Key | |||
| FK_PurchaseOrderHeader_Employee_EmployeeID | EmployeeID ↗ ❏ HumanResources.Employee(BusinessEntityID) | ||
| FK_PurchaseOrderHeader_ShipMethod_ShipMethodID | ShipMethodID ↗ ❏ Purchasing.ShipMethod | ||
| FK_PurchaseOrderHeader_Vendor_VendorID | VendorID ↗ ❏ Purchasing.Vendor(BusinessEntityID) | ||
| Referring Foreign Key | |||
| FK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderID | PurchaseOrderID ↙ ❏ Purchasing.PurchaseOrderDetail | ||
| Constraints | |||
| CK_PurchaseOrderHeader_Status | [Status]>=(1) AND [Status]<=(4) | ||
| CK_PurchaseOrderHeader_ShipDate | [ShipDate]>=[OrderDate] OR [ShipDate] IS NULL | ||
| CK_PurchaseOrderHeader_SubTotal | [SubTotal]>=(0.00) | ||
| CK_PurchaseOrderHeader_TaxAmt | [TaxAmt]>=(0.00) | ||
| CK_PurchaseOrderHeader_Freight | [Freight]>=(0.00) | ||
| Triggers | |||
| uPurchaseOrderHeader | CREATE TRIGGER [Purchasing].[${nameWithSchemaName}] ON [Purchasing].[PurchaseOrderHeader]
AFTER UPDATE AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
-- Update RevisionNumber for modification of any field EXCEPT the Status.
IF NOT UPDATE([Status])
BEGIN
UPDATE [Purchasing].[PurchaseOrderHeader]
SET [Purchasing].[PurchaseOrderHeader].[RevisionNumber] =
[Purchasing].[PurchaseOrderHeader].[RevisionNumber] + 1
WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] IN
(SELECT inserted.[PurchaseOrderID] FROM inserted);
END;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END | ||
Shipping company lookup table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ShipMethodID | int NOT NULL IDENTITY | Primary key for ShipMethod records. |
| * | Name | Purchasing.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Shipping company name. |
| * | ShipBase | money NOT NULL DEFAULT 0.00 | Minimum shipping charge. |
| * | ShipRate | money NOT NULL DEFAULT 0.00 | Shipping charge per pound. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ShipMethod_ShipMethodID | Primary Key ON ShipMethodID | ||
| AK_ShipMethod_Name | Unique Index ON Name | ||
| AK_ShipMethod_rowguid | Unique Index ON rowguid | ||
| Referring Foreign Key | |||
| FK_PurchaseOrderHeader_ShipMethod_ShipMethodID | ShipMethodID ↙ ❏ Purchasing.PurchaseOrderHeader | ||
| FK_SalesOrderHeader_ShipMethod_ShipMethodID | ShipMethodID ↙ ❏ Sales.SalesOrderHeader | ||
| Constraints | |||
| CK_ShipMethod_ShipBase | [ShipBase]>(0.00) | ||
| CK_ShipMethod_ShipRate | [ShipRate]>(0.00) | ||
Companies from whom Adventure Works Cycles purchases parts or other goods.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key for Vendor records. Foreign key to BusinessEntity.BusinessEntityID |
| * | AccountNumber | Purchasing.AccountNumber NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Vendor account (identification) number. |
| * | Name | Purchasing.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Company name. |
| * | CreditRating | tinyint NOT NULL | 1 = Superior, 2 = Excellent, 3 = Above average, 4 = Average, 5 = Below average |
| * | PreferredVendorStatus | Purchasing.Flag NOT NULL DEFAULT ((1)) | 0 = Do not use if another vendor is available. 1 = Preferred over other vendors supplying the same product. |
| * | ActiveFlag | Purchasing.Flag NOT NULL DEFAULT ((1)) | 0 = Vendor no longer used. 1 = Vendor is actively used. |
| PurchasingWebServiceURL | nvarchar(1024) COLLATE SQL_Latin1_General_CP1_CI_AS | ||
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | |
| Indexes | |||
| PK_Vendor_BusinessEntityID | Primary Key ON BusinessEntityID | ||
| AK_Vendor_AccountNumber | Unique Index ON AccountNumber | ||
| Foreign Key | |||
| FK_Vendor_BusinessEntity_BusinessEntityID | BusinessEntityID ↗ ❏ Person.BusinessEntity | ||
| Referring Foreign Key | |||
| FK_ProductVendor_Vendor_BusinessEntityID | BusinessEntityID ↙ ❏ Purchasing.ProductVendor | ||
| FK_PurchaseOrderHeader_Vendor_VendorID | BusinessEntityID ↙ ❏ Purchasing.PurchaseOrderHeader(VendorID) | ||
| Constraints | |||
| CK_Vendor_CreditRating | [CreditRating]>=(1) AND [CreditRating]<=(5) | ||
| Triggers | |||
| dVendor | CREATE TRIGGER [Purchasing].[${nameWithSchemaName}] ON [Purchasing].[Vendor]
INSTEAD OF DELETE NOT FOR REPLICATION AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
DECLARE @DeleteCount int;
SELECT @DeleteCount = COUNT(*) FROM deleted;
IF @DeleteCount > 0
BEGIN
RAISERROR
(N'Vendors cannot be deleted. They can only be marked as not active.', -- Message
10, -- Severity.
1); -- State.
-- Rollback any active or uncommittable transactions
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
END;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END | ||
Cross-reference table mapping ISO currency codes to a country or region.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | CountryRegionCode | nvarchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | ISO code for countries and regions. Foreign key to CountryRegion.CountryRegionCode. |
| * | CurrencyCode | nchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | ISO standard currency code. Foreign key to Currency.CurrencyCode. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode | Primary Key ON CountryRegionCode, CurrencyCode | ||
| IX_CountryRegionCurrency_CurrencyCode | Index ON CurrencyCode | ||
| Foreign Key | |||
| FK_CountryRegionCurrency_CountryRegion_CountryRegionCode | CountryRegionCode ↗ ❏ Person.CountryRegion | ||
| FK_CountryRegionCurrency_Currency_CurrencyCode | CurrencyCode ↗ ❏ Sales.Currency | ||
Customer credit card information.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | CreditCardID | int NOT NULL IDENTITY | Primary key for CreditCard records. |
| * | CardType | nvarchar(50) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Credit card name. |
| * | CardNumber | nvarchar(25) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Credit card number. |
| * | ExpMonth | tinyint NOT NULL | Credit card expiration month. |
| * | ExpYear | smallint NOT NULL | Credit card expiration year. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_CreditCard_CreditCardID | Primary Key ON CreditCardID | ||
| AK_CreditCard_CardNumber | Unique Index ON CardNumber | ||
| Referring Foreign Key | |||
| FK_PersonCreditCard_CreditCard_CreditCardID | CreditCardID ↙ ❏ Sales.PersonCreditCard | ||
| FK_SalesOrderHeader_CreditCard_CreditCardID | CreditCardID ↙ ❏ Sales.SalesOrderHeader | ||
Lookup table containing standard ISO currencies.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | CurrencyCode | nchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | The ISO code for the Currency. |
| * | Name | Sales.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Currency name. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Currency_CurrencyCode | Primary Key ON CurrencyCode | ||
| AK_Currency_Name | Unique Index ON Name | ||
| Referring Foreign Key | |||
| FK_CountryRegionCurrency_Currency_CurrencyCode | CurrencyCode ↙ ❏ Sales.CountryRegionCurrency | ||
| FK_CurrencyRate_Currency_FromCurrencyCode | CurrencyCode ↙ ❏ Sales.CurrencyRate(FromCurrencyCode) | ||
| FK_CurrencyRate_Currency_ToCurrencyCode | CurrencyCode ↙ ❏ Sales.CurrencyRate(ToCurrencyCode) | ||
Currency exchange rates.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | CurrencyRateID | int NOT NULL IDENTITY | Primary key for CurrencyRate records. |
| * | CurrencyRateDate | datetime NOT NULL | Date and time the exchange rate was obtained. |
| * | FromCurrencyCode | nchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Exchange rate was converted from this currency code. |
| * | ToCurrencyCode | nchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Exchange rate was converted to this currency code. |
| * | AverageRate | money NOT NULL | Average exchange rate for the day. |
| * | EndOfDayRate | money NOT NULL | Final exchange rate for the day. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_CurrencyRate_CurrencyRateID | Primary Key ON CurrencyRateID | ||
| AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode | Unique Index ON CurrencyRateDate, FromCurrencyCode, ToCurrencyCode | ||
| Foreign Key | |||
| FK_CurrencyRate_Currency_FromCurrencyCode | FromCurrencyCode ↗ ❏ Sales.Currency(CurrencyCode) | ||
| FK_CurrencyRate_Currency_ToCurrencyCode | ToCurrencyCode ↗ ❏ Sales.Currency(CurrencyCode) | ||
| Referring Foreign Key | |||
| FK_SalesOrderHeader_CurrencyRate_CurrencyRateID | CurrencyRateID ↙ ❏ Sales.SalesOrderHeader | ||
Current customer information. Also see the Person and Store tables.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | CustomerID | int NOT NULL IDENTITY | Primary key. |
| PersonID | int | Foreign key to Person.BusinessEntityID | |
| StoreID | int | Foreign key to Store.BusinessEntityID | |
| TerritoryID | int | ID of the territory in which the customer is located. Foreign key to SalesTerritory.SalesTerritoryID. | |
| AccountNumber | text COLLATE SQL_Latin1_General_CP1_CI_AS | Unique number identifying the customer assigned by the accounting system. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Customer_CustomerID | Primary Key ON CustomerID | ||
| AK_Customer_rowguid | Unique Index ON rowguid | ||
| AK_Customer_AccountNumber | Unique Index ON AccountNumber | ||
| IX_Customer_TerritoryID | Index ON TerritoryID | ||
| Foreign Key | |||
| FK_Customer_Person_PersonID | PersonID ↗ ❏ Person.Person(BusinessEntityID) | ||
| FK_Customer_SalesTerritory_TerritoryID | TerritoryID ↗ ❏ Sales.SalesTerritory | ||
| FK_Customer_Store_StoreID | StoreID ↗ ❏ Sales.Store(BusinessEntityID) | ||
| Referring Foreign Key | |||
| FK_SalesOrderHeader_Customer_CustomerID | CustomerID ↙ ❏ Sales.SalesOrderHeader | ||
Cross-reference table mapping people to their credit card information in the CreditCard table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Business entity identification number. Foreign key to Person.BusinessEntityID. |
| * | CreditCardID | int NOT NULL | Credit card identification number. Foreign key to CreditCard.CreditCardID. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_PersonCreditCard_BusinessEntityID_CreditCardID | Primary Key ON BusinessEntityID, CreditCardID | ||
| Foreign Key | |||
| FK_PersonCreditCard_CreditCard_CreditCardID | CreditCardID ↗ ❏ Sales.CreditCard | ||
| FK_PersonCreditCard_Person_BusinessEntityID | BusinessEntityID ↗ ❏ Person.Person | ||
Individual products associated with a specific sales order. See SalesOrderHeader.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | SalesOrderID | int NOT NULL | Primary key. Foreign key to SalesOrderHeader.SalesOrderID. |
| * | SalesOrderDetailID | int NOT NULL IDENTITY | Primary key. One incremental unique number per product sold. |
| CarrierTrackingNumber | nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS | Shipment tracking number supplied by the shipper. | |
| * | OrderQty | smallint NOT NULL | Quantity ordered per product. |
| * | ProductID | int NOT NULL | Product sold to customer. Foreign key to Product.ProductID. |
| * | SpecialOfferID | int NOT NULL | Promotional code. Foreign key to SpecialOffer.SpecialOfferID. |
| * | UnitPrice | money NOT NULL | Selling price of a single product. |
| * | UnitPriceDiscount | money NOT NULL DEFAULT 0.0 | Discount amount. |
| LineTotal | text | Per product subtotal. Computed as UnitPrice * (1 - UnitPriceDiscount) * OrderQty. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID | Primary Key ON SalesOrderID, SalesOrderDetailID | ||
| AK_SalesOrderDetail_rowguid | Unique Index ON rowguid | ||
| IX_SalesOrderDetail_ProductID | Index ON ProductID | ||
| Foreign Key | |||
| FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID | SalesOrderID ↗ ❏ Sales.SalesOrderHeader on delete cascade | ||
| FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID | SpecialOfferID, ProductID ↗ ❏ Sales.SpecialOfferProduct | ||
| Constraints | |||
| CK_SalesOrderDetail_OrderQty | [OrderQty]>(0) | ||
| CK_SalesOrderDetail_UnitPrice | [UnitPrice]>=(0.00) | ||
| CK_SalesOrderDetail_UnitPriceDiscount | [UnitPriceDiscount]>=(0.00) | ||
| Triggers | |||
| iduSalesOrderDetail | CREATE TRIGGER [Sales].[${nameWithSchemaName}] ON [Sales].[SalesOrderDetail]
AFTER INSERT, DELETE, UPDATE AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
-- If inserting or updating these columns
IF UPDATE([ProductID]) OR UPDATE([OrderQty]) OR UPDATE([UnitPrice]) OR UPDATE([UnitPriceDiscount])
-- Insert record into TransactionHistory
BEGIN
INSERT INTO [Production].[TransactionHistory]
([ProductID]
,[ReferenceOrderID]
,[ReferenceOrderLineID]
,[TransactionType]
,[TransactionDate]
,[Quantity]
,[ActualCost])
SELECT
inserted.[ProductID]
,inserted.[SalesOrderID]
,inserted.[SalesOrderDetailID]
,'S'
,GETDATE()
,inserted.[OrderQty]
,inserted.[UnitPrice]
FROM inserted
INNER JOIN [Sales].[SalesOrderHeader]
ON inserted.[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID];
UPDATE [Person].[Person]
SET [Demographics].modify('declare default element namespace
"http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
replace value of (/IndividualSurvey/TotalPurchaseYTD)[1]
with data(/IndividualSurvey/TotalPurchaseYTD)[1] + sql:column ("inserted.LineTotal")')
FROM inserted
INNER JOIN [Sales].[SalesOrderHeader] AS SOH
ON inserted.[SalesOrderID] = SOH.[SalesOrderID]
INNER JOIN [Sales].[Customer] AS C
ON SOH.[CustomerID] = C.[CustomerID]
WHERE C.[PersonID] = [Person].[Person].[BusinessEntityID];
END;
-- Update SubTotal in SalesOrderHeader record. Note that this causes the
-- SalesOrderHeader trigger to fire which will update the RevisionNumber.
UPDATE [Sales].[SalesOrderHeader]
SET [Sales].[SalesOrderHeader].[SubTotal] =
(SELECT SUM([Sales].[SalesOrderDetail].[LineTotal])
FROM [Sales].[SalesOrderDetail]
WHERE [Sales].[SalesOrderHeader].[SalesOrderID] = [Sales].[SalesOrderDetail].[SalesOrderID])
WHERE [Sales].[SalesOrderHeader].[SalesOrderID] IN (SELECT inserted.[SalesOrderID] FROM inserted);
UPDATE [Person].[Person]
SET [Demographics].modify('declare default element namespace
"http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
replace value of (/IndividualSurvey/TotalPurchaseYTD)[1]
with data(/IndividualSurvey/TotalPurchaseYTD)[1] - sql:column("deleted.LineTotal")')
FROM deleted
INNER JOIN [Sales].[SalesOrderHeader]
ON deleted.[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID]
INNER JOIN [Sales].[Customer]
ON [Sales].[Customer].[CustomerID] = [Sales].[SalesOrderHeader].[CustomerID]
WHERE [Sales].[Customer].[PersonID] = [Person].[Person].[BusinessEntityID];
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END | ||
General sales order information.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | SalesOrderID | int NOT NULL IDENTITY | Primary key. |
| * | RevisionNumber | tinyint NOT NULL DEFAULT 0 | Incremental number to track changes to the sales order over time. |
| * | OrderDate | datetime NOT NULL DEFAULT getdate() | Dates the sales order was created. |
| * | DueDate | datetime NOT NULL | Date the order is due to the customer. |
| ShipDate | datetime | Date the order was shipped to the customer. | |
| * | Status | tinyint NOT NULL DEFAULT 1 | Order current status. 1 = In process; 2 = Approved; 3 = Backordered; 4 = Rejected; 5 = Shipped; 6 = Cancelled |
| * | OnlineOrderFlag | Sales.Flag NOT NULL DEFAULT ((1)) | 0 = Order placed by sales person. 1 = Order placed online by customer. |
| SalesOrderNumber | text COLLATE SQL_Latin1_General_CP1_CI_AS | Unique sales order identification number. | |
| PurchaseOrderNumber | Sales.OrderNumber COLLATE SQL_Latin1_General_CP1_CI_AS | Customer purchase order number reference. | |
| AccountNumber | Sales.AccountNumber COLLATE SQL_Latin1_General_CP1_CI_AS | Financial accounting number reference. | |
| * | CustomerID | int NOT NULL | Customer identification number. Foreign key to Customer.BusinessEntityID. |
| SalesPersonID | int | Sales person who created the sales order. Foreign key to SalesPerson.BusinessEntityID. | |
| TerritoryID | int | Territory in which the sale was made. Foreign key to SalesTerritory.SalesTerritoryID. | |
| * | BillToAddressID | int NOT NULL | Customer billing address. Foreign key to Address.AddressID. |
| * | ShipToAddressID | int NOT NULL | Customer shipping address. Foreign key to Address.AddressID. |
| * | ShipMethodID | int NOT NULL | Shipping method. Foreign key to ShipMethod.ShipMethodID. |
| CreditCardID | int | Credit card identification number. Foreign key to CreditCard.CreditCardID. | |
| CreditCardApprovalCode | varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS | Approval code provided by the credit card company. | |
| CurrencyRateID | int | Currency exchange rate used. Foreign key to CurrencyRate.CurrencyRateID. | |
| * | SubTotal | money NOT NULL DEFAULT 0.00 | Sales subtotal. Computed as SUM(SalesOrderDetail.LineTotal)for the appropriate SalesOrderID. |
| * | TaxAmt | money NOT NULL DEFAULT 0.00 | Tax amount. |
| * | Freight | money NOT NULL DEFAULT 0.00 | Shipping cost. |
| TotalDue | text | Total due from customer. Computed as Subtotal + TaxAmt + Freight. | |
| Comment | nvarchar(128) COLLATE SQL_Latin1_General_CP1_CI_AS | Sales representative comments. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesOrderHeader_SalesOrderID | Primary Key ON SalesOrderID | ||
| AK_SalesOrderHeader_rowguid | Unique Index ON rowguid | ||
| AK_SalesOrderHeader_SalesOrderNumber | Unique Index ON SalesOrderNumber | ||
| IX_SalesOrderHeader_CustomerID | Index ON CustomerID | ||
| IX_SalesOrderHeader_SalesPersonID | Index ON SalesPersonID | ||
| Foreign Key | |||
| FK_SalesOrderHeader_Address_BillToAddressID | BillToAddressID ↗ ❏ Person.Address(AddressID) | ||
| FK_SalesOrderHeader_Address_ShipToAddressID | ShipToAddressID ↗ ❏ Person.Address(AddressID) | ||
| FK_SalesOrderHeader_CreditCard_CreditCardID | CreditCardID ↗ ❏ Sales.CreditCard | ||
| FK_SalesOrderHeader_CurrencyRate_CurrencyRateID | CurrencyRateID ↗ ❏ Sales.CurrencyRate | ||
| FK_SalesOrderHeader_Customer_CustomerID | CustomerID ↗ ❏ Sales.Customer | ||
| FK_SalesOrderHeader_SalesPerson_SalesPersonID | SalesPersonID ↗ ❏ Sales.SalesPerson(BusinessEntityID) | ||
| FK_SalesOrderHeader_SalesTerritory_TerritoryID | TerritoryID ↗ ❏ Sales.SalesTerritory | ||
| FK_SalesOrderHeader_ShipMethod_ShipMethodID | ShipMethodID ↗ ❏ Purchasing.ShipMethod | ||
| Referring Foreign Key | |||
| FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID | SalesOrderID ↙ ❏ Sales.SalesOrderDetail | ||
| FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID | SalesOrderID ↙ ❏ Sales.SalesOrderHeaderSalesReason | ||
| Constraints | |||
| CK_SalesOrderHeader_Status | [Status]>=(0) AND [Status]<=(8) | ||
| CK_SalesOrderHeader_DueDate | [DueDate]>=[OrderDate] | ||
| CK_SalesOrderHeader_ShipDate | [ShipDate]>=[OrderDate] OR [ShipDate] IS NULL | ||
| CK_SalesOrderHeader_SubTotal | [SubTotal]>=(0.00) | ||
| CK_SalesOrderHeader_TaxAmt | [TaxAmt]>=(0.00) | ||
| CK_SalesOrderHeader_Freight | [Freight]>=(0.00) | ||
| Triggers | |||
| uSalesOrderHeader | CREATE TRIGGER [Sales].[${nameWithSchemaName}] ON [Sales].[SalesOrderHeader]
AFTER UPDATE NOT FOR REPLICATION AS
BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0
RETURN;
SET NOCOUNT ON;
BEGIN TRY
-- Update RevisionNumber for modification of any field EXCEPT the Status.
IF NOT UPDATE([Status])
BEGIN
UPDATE [Sales].[SalesOrderHeader]
SET [Sales].[SalesOrderHeader].[RevisionNumber] =
[Sales].[SalesOrderHeader].[RevisionNumber] + 1
WHERE [Sales].[SalesOrderHeader].[SalesOrderID] IN
(SELECT inserted.[SalesOrderID] FROM inserted);
END;
-- Update the SalesPerson SalesYTD when SubTotal is updated
IF UPDATE([SubTotal])
BEGIN
DECLARE @StartDate datetime,
@EndDate datetime
SET @StartDate = [dbo].[ufnGetAccountingStartDate]();
SET @EndDate = [dbo].[ufnGetAccountingEndDate]();
UPDATE [Sales].[SalesPerson]
SET [Sales].[SalesPerson].[SalesYTD] =
(SELECT SUM([Sales].[SalesOrderHeader].[SubTotal])
FROM [Sales].[SalesOrderHeader]
WHERE [Sales].[SalesPerson].[BusinessEntityID] = [Sales].[SalesOrderHeader].[SalesPersonID]
AND ([Sales].[SalesOrderHeader].[Status] = 5) -- Shipped
AND [Sales].[SalesOrderHeader].[OrderDate] BETWEEN @StartDate AND @EndDate)
WHERE [Sales].[SalesPerson].[BusinessEntityID]
IN (SELECT DISTINCT inserted.[SalesPersonID] FROM inserted
WHERE inserted.[OrderDate] BETWEEN @StartDate AND @EndDate);
-- Update the SalesTerritory SalesYTD when SubTotal is updated
UPDATE [Sales].[SalesTerritory]
SET [Sales].[SalesTerritory].[SalesYTD] =
(SELECT SUM([Sales].[SalesOrderHeader].[SubTotal])
FROM [Sales].[SalesOrderHeader]
WHERE [Sales].[SalesTerritory].[TerritoryID] = [Sales].[SalesOrderHeader].[TerritoryID]
AND ([Sales].[SalesOrderHeader].[Status] = 5) -- Shipped
AND [Sales].[SalesOrderHeader].[OrderDate] BETWEEN @StartDate AND @EndDate)
WHERE [Sales].[SalesTerritory].[TerritoryID]
IN (SELECT DISTINCT inserted.[TerritoryID] FROM inserted
WHERE inserted.[OrderDate] BETWEEN @StartDate AND @EndDate);
END;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END | ||
Cross-reference table mapping sales orders to sales reason codes.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | SalesOrderID | int NOT NULL | Primary key. Foreign key to SalesOrderHeader.SalesOrderID. |
| * | SalesReasonID | int NOT NULL | Primary key. Foreign key to SalesReason.SalesReasonID. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesOrderHeaderSalesReason_SalesOrderID_SalesReasonID | Primary Key ON SalesOrderID, SalesReasonID | ||
| Foreign Key | |||
| FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID | SalesOrderID ↗ ❏ Sales.SalesOrderHeader on delete cascade | ||
| FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID | SalesReasonID ↗ ❏ Sales.SalesReason | ||
Sales representative current information.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key for SalesPerson records. Foreign key to Employee.BusinessEntityID |
| TerritoryID | int | Territory currently assigned to. Foreign key to SalesTerritory.SalesTerritoryID. | |
| SalesQuota | money | Projected yearly sales. | |
| * | Bonus | money NOT NULL DEFAULT 0.00 | Bonus due if quota is met. |
| * | CommissionPct | smallmoney NOT NULL DEFAULT 0.00 | Commision percent received per sale. |
| * | SalesYTD | money NOT NULL DEFAULT 0.00 | Sales total year to date. |
| * | SalesLastYear | money NOT NULL DEFAULT 0.00 | Sales total of previous year. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesPerson_BusinessEntityID | Primary Key ON BusinessEntityID | ||
| AK_SalesPerson_rowguid | Unique Index ON rowguid | ||
| Foreign Key | |||
| FK_SalesPerson_Employee_BusinessEntityID | BusinessEntityID ↗ ❏ HumanResources.Employee | ||
| FK_SalesPerson_SalesTerritory_TerritoryID | TerritoryID ↗ ❏ Sales.SalesTerritory | ||
| Referring Foreign Key | |||
| FK_SalesOrderHeader_SalesPerson_SalesPersonID | BusinessEntityID ↙ ❏ Sales.SalesOrderHeader(SalesPersonID) | ||
| FK_SalesPersonQuotaHistory_SalesPerson_BusinessEntityID | BusinessEntityID ↙ ❏ Sales.SalesPersonQuotaHistory | ||
| FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID | BusinessEntityID ↙ ❏ Sales.SalesTerritoryHistory | ||
| FK_Store_SalesPerson_SalesPersonID | BusinessEntityID ↙ ❏ Sales.Store(SalesPersonID) | ||
| Constraints | |||
| CK_SalesPerson_SalesQuota | [SalesQuota]>(0.00) | ||
| CK_SalesPerson_Bonus | [Bonus]>=(0.00) | ||
| CK_SalesPerson_CommissionPct | [CommissionPct]>=(0.00) | ||
| CK_SalesPerson_SalesYTD | [SalesYTD]>=(0.00) | ||
| CK_SalesPerson_SalesLastYear | [SalesLastYear]>=(0.00) | ||
Sales performance tracking.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Sales person identification number. Foreign key to SalesPerson.BusinessEntityID. |
| * | QuotaDate | datetime NOT NULL | Sales quota date. |
| * | SalesQuota | money NOT NULL | Sales quota amount. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesPersonQuotaHistory_BusinessEntityID_QuotaDate | Primary Key ON BusinessEntityID, QuotaDate | ||
| AK_SalesPersonQuotaHistory_rowguid | Unique Index ON rowguid | ||
| Foreign Key | |||
| FK_SalesPersonQuotaHistory_SalesPerson_BusinessEntityID | BusinessEntityID ↗ ❏ Sales.SalesPerson | ||
| Constraints | |||
| CK_SalesPersonQuotaHistory_SalesQuota | [SalesQuota]>(0.00) | ||
Lookup table of customer purchase reasons.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | SalesReasonID | int NOT NULL IDENTITY | Primary key for SalesReason records. |
| * | Name | Sales.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Sales reason description. |
| * | ReasonType | Sales.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Category the sales reason belongs to. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesReason_SalesReasonID | Primary Key ON SalesReasonID | ||
| Referring Foreign Key | |||
| FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID | SalesReasonID ↙ ❏ Sales.SalesOrderHeaderSalesReason | ||
Tax rate lookup table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | SalesTaxRateID | int NOT NULL IDENTITY | Primary key for SalesTaxRate records. |
| * | StateProvinceID | int NOT NULL | State, province, or country/region the sales tax applies to. |
| * | TaxType | tinyint NOT NULL | 1 = Tax applied to retail transactions, 2 = Tax applied to wholesale transactions, 3 = Tax applied to all sales (retail and wholesale) transactions. |
| * | TaxRate | smallmoney NOT NULL DEFAULT 0.00 | Tax rate amount. |
| * | Name | Sales.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Tax rate description. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesTaxRate_SalesTaxRateID | Primary Key ON SalesTaxRateID | ||
| AK_SalesTaxRate_StateProvinceID_TaxType | Unique Index ON StateProvinceID, TaxType | ||
| AK_SalesTaxRate_rowguid | Unique Index ON rowguid | ||
| Foreign Key | |||
| FK_SalesTaxRate_StateProvince_StateProvinceID | StateProvinceID ↗ ❏ Person.StateProvince | ||
| Constraints | |||
| CK_SalesTaxRate_TaxType | [TaxType]>=(1) AND [TaxType]<=(3) | ||
Sales territory lookup table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | TerritoryID | int NOT NULL IDENTITY | Primary key for SalesTerritory records. |
| * | Name | Sales.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Sales territory description |
| * | CountryRegionCode | nvarchar(3) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | ISO standard country or region code. Foreign key to CountryRegion.CountryRegionCode. |
| * | Group | nvarchar(50) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Geographic area to which the sales territory belong. |
| * | SalesYTD | money NOT NULL DEFAULT 0.00 | Sales in the territory year to date. |
| * | SalesLastYear | money NOT NULL DEFAULT 0.00 | Sales in the territory the previous year. |
| * | CostYTD | money NOT NULL DEFAULT 0.00 | Business costs in the territory year to date. |
| * | CostLastYear | money NOT NULL DEFAULT 0.00 | Business costs in the territory the previous year. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesTerritory_TerritoryID | Primary Key ON TerritoryID | ||
| AK_SalesTerritory_Name | Unique Index ON Name | ||
| AK_SalesTerritory_rowguid | Unique Index ON rowguid | ||
| Foreign Key | |||
| FK_SalesTerritory_CountryRegion_CountryRegionCode | CountryRegionCode ↗ ❏ Person.CountryRegion | ||
| Referring Foreign Key | |||
| FK_StateProvince_SalesTerritory_TerritoryID | TerritoryID ↙ ❏ Person.StateProvince | ||
| FK_Customer_SalesTerritory_TerritoryID | TerritoryID ↙ ❏ Sales.Customer | ||
| FK_SalesOrderHeader_SalesTerritory_TerritoryID | TerritoryID ↙ ❏ Sales.SalesOrderHeader | ||
| FK_SalesPerson_SalesTerritory_TerritoryID | TerritoryID ↙ ❏ Sales.SalesPerson | ||
| FK_SalesTerritoryHistory_SalesTerritory_TerritoryID | TerritoryID ↙ ❏ Sales.SalesTerritoryHistory | ||
| Constraints | |||
| CK_SalesTerritory_SalesYTD | [SalesYTD]>=(0.00) | ||
| CK_SalesTerritory_SalesLastYear | [SalesLastYear]>=(0.00) | ||
| CK_SalesTerritory_CostYTD | [CostYTD]>=(0.00) | ||
| CK_SalesTerritory_CostLastYear | [CostLastYear]>=(0.00) | ||
Sales representative transfers to other sales territories.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key. The sales rep. Foreign key to SalesPerson.BusinessEntityID. |
| * | TerritoryID | int NOT NULL | Primary key. Territory identification number. Foreign key to SalesTerritory.SalesTerritoryID. |
| * | StartDate | datetime NOT NULL | Primary key. Date the sales representive started work in the territory. |
| EndDate | datetime | Date the sales representative left work in the territory. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SalesTerritoryHistory_BusinessEntityID_StartDate_TerritoryID | Primary Key ON BusinessEntityID, StartDate, TerritoryID | ||
| AK_SalesTerritoryHistory_rowguid | Unique Index ON rowguid | ||
| Foreign Key | |||
| FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID | BusinessEntityID ↗ ❏ Sales.SalesPerson | ||
| FK_SalesTerritoryHistory_SalesTerritory_TerritoryID | TerritoryID ↗ ❏ Sales.SalesTerritory | ||
| Constraints | |||
| CK_SalesTerritoryHistory_EndDate | [EndDate]>=[StartDate] OR [EndDate] IS NULL | ||
Contains online customer orders until the order is submitted or cancelled.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ShoppingCartItemID | int NOT NULL IDENTITY | Primary key for ShoppingCartItem records. |
| * | ShoppingCartID | nvarchar(50) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Shopping cart identification number. |
| * | Quantity | int NOT NULL DEFAULT 1 | Product quantity ordered. |
| * | ProductID | int NOT NULL | Product ordered. Foreign key to Product.ProductID. |
| * | DateCreated | datetime NOT NULL DEFAULT getdate() | Date the time the record was created. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_ShoppingCartItem_ShoppingCartItemID | Primary Key ON ShoppingCartItemID | ||
| IX_ShoppingCartItem_ShoppingCartID_ProductID | Index ON ShoppingCartID, ProductID | ||
| Foreign Key | |||
| FK_ShoppingCartItem_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| Constraints | |||
| CK_ShoppingCartItem_Quantity | [Quantity]>=(1) | ||
Sale discounts lookup table.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | SpecialOfferID | int NOT NULL IDENTITY | Primary key for SpecialOffer records. |
| * | Description | nvarchar(255) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Discount description. |
| * | DiscountPct | smallmoney NOT NULL DEFAULT 0.00 | Discount precentage. |
| * | Type | nvarchar(50) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Discount type category. |
| * | Category | nvarchar(50) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Group the discount applies to such as Reseller or Customer. |
| * | StartDate | datetime NOT NULL | Discount start date. |
| * | EndDate | datetime NOT NULL | Discount end date. |
| * | MinQty | int NOT NULL DEFAULT 0 | Minimum discount percent allowed. |
| MaxQty | int | Maximum discount percent allowed. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SpecialOffer_SpecialOfferID | Primary Key ON SpecialOfferID | ||
| AK_SpecialOffer_rowguid | Unique Index ON rowguid | ||
| Referring Foreign Key | |||
| FK_SpecialOfferProduct_SpecialOffer_SpecialOfferID | SpecialOfferID ↙ ❏ Sales.SpecialOfferProduct | ||
| Constraints | |||
| CK_SpecialOffer_EndDate | [EndDate]>=[StartDate] | ||
| CK_SpecialOffer_DiscountPct | [DiscountPct]>=(0.00) | ||
| CK_SpecialOffer_MinQty | [MinQty]>=(0) | ||
| CK_SpecialOffer_MaxQty | [MaxQty]>=(0) | ||
Cross-reference table mapping products to special offer discounts.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | SpecialOfferID | int NOT NULL | Primary key for SpecialOfferProduct records. |
| * | ProductID | int NOT NULL | Product identification number. Foreign key to Product.ProductID. |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_SpecialOfferProduct_SpecialOfferID_ProductID | Primary Key ON SpecialOfferID, ProductID | ||
| AK_SpecialOfferProduct_rowguid | Unique Index ON rowguid | ||
| IX_SpecialOfferProduct_ProductID | Index ON ProductID | ||
| Foreign Key | |||
| FK_SpecialOfferProduct_Product_ProductID | ProductID ↗ ❏ Production.Product | ||
| FK_SpecialOfferProduct_SpecialOffer_SpecialOfferID | SpecialOfferID ↗ ❏ Sales.SpecialOffer | ||
| Referring Foreign Key | |||
| FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID | SpecialOfferID, ProductID ↙ ❏ Sales.SalesOrderDetail | ||
Customers (resellers) of Adventure Works products.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | BusinessEntityID | int NOT NULL | Primary key. Foreign key to Customer.BusinessEntityID. |
| * | Name | Sales.Name NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Name of the store. |
| SalesPersonID | int | ID of the sales person assigned to the customer. Foreign key to SalesPerson.BusinessEntityID. | |
| Demographics | xml | Demographic informationg about the store such as the number of employees, annual sales and store type. | |
| * | rowguid | uniqueidentifier NOT NULL DEFAULT newid() | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_Store_BusinessEntityID | Primary Key ON BusinessEntityID | ||
| AK_Store_rowguid | Unique Index ON rowguid | ||
| IX_Store_SalesPersonID | Index ON SalesPersonID | ||
| Foreign Key | |||
| FK_Store_BusinessEntity_BusinessEntityID | BusinessEntityID ↗ ❏ Person.BusinessEntity | ||
| FK_Store_SalesPerson_SalesPersonID | SalesPersonID ↗ ❏ Sales.SalesPerson(BusinessEntityID) | ||
| Referring Foreign Key | |||
| FK_Customer_Store_StoreID | BusinessEntityID ↙ ❏ Sales.Customer(StoreID) | ||
Current version number of the AdventureWorks 2025 sample database.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | SystemInformationID | tinyint NOT NULL IDENTITY | Primary key for AWBuildVersion records. |
| * | Database Version | nvarchar(25) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | Version number of the database in 9.yy.mm.dd.00 format. |
| * | VersionDate | datetime NOT NULL | Date and time the record was last updated. |
| * | ModifiedDate | datetime NOT NULL DEFAULT getdate() | Date and time the record was last updated. |
| Indexes | |||
| PK_AWBuildVersion_SystemInformationID | Primary Key ON SystemInformationID | ||
Audit table tracking all DDL changes made to the AdventureWorks database. Data is captured by the database trigger ddlDatabaseTriggerLog.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | DatabaseLogID | int NOT NULL IDENTITY | Primary key for DatabaseLog records. |
| * | PostTime | datetime NOT NULL | The date and time the DDL change occurred. |
| * | DatabaseUser | sysname NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | The user who implemented the DDL change. |
| * | Event | sysname NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | The type of DDL statement that was executed. |
| Schema | sysname COLLATE SQL_Latin1_General_CP1_CI_AS | The schema to which the changed object belongs. | |
| Object | sysname COLLATE SQL_Latin1_General_CP1_CI_AS | The object that was changed by the DDL statment. | |
| * | TSQL | nvarchar(max) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | The exact Transact-SQL statement that was executed. |
| * | XmlEvent | xml NOT NULL | The raw XML data generated by database trigger. |
| Indexes | |||
| PK_DatabaseLog_DatabaseLogID | Primary Key ON DatabaseLogID | ||
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.
| Idx | Column Name | Definition | Description |
|---|---|---|---|
| * | ErrorLogID | int NOT NULL IDENTITY | Primary key for ErrorLog records. |
| * | ErrorTime | datetime NOT NULL DEFAULT getdate() | The date and time at which the error occurred. |
| * | UserName | sysname NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | The user who executed the batch in which the error occurred. |
| * | ErrorNumber | int NOT NULL | The error number of the error that occurred. |
| ErrorSeverity | int | The severity of the error that occurred. | |
| ErrorState | int | The state number of the error that occurred. | |
| ErrorProcedure | nvarchar(126) COLLATE SQL_Latin1_General_CP1_CI_AS | The name of the stored procedure or trigger where the error occurred. | |
| ErrorLine | int | The line number at which the error occurred. | |
| * | ErrorMessage | nvarchar(4000) NOT NULL COLLATE SQL_Latin1_General_CP1_CI_AS | The message text of the error that occurred. |
| Indexes | |||
| PK_ErrorLog_ErrorLogID | Primary Key ON ErrorLogID | ||
| AdventureWorks2025.HumanResources.uspUpdateEmployeeHireInfo | |
CREATE PROCEDURE [HumanResources].[uspUpdateEmployeeHireInfo]
@BusinessEntityID [int],
@JobTitle [nvarchar](50),
@HireDate [datetime],
@RateChangeDate [datetime],
@Rate [money],
@PayFrequency [tinyint],
@CurrentFlag [dbo].[Flag]
WITH EXECUTE AS CALLER
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
BEGIN TRANSACTION;
UPDATE [HumanResources].[Employee]
SET [JobTitle] = @JobTitle
,[HireDate] = @HireDate
,[CurrentFlag] = @CurrentFlag
WHERE [BusinessEntityID] = @BusinessEntityID;
INSERT INTO [HumanResources].[EmployeePayHistory]
([BusinessEntityID]
,[RateChangeDate]
,[Rate]
,[PayFrequency])
VALUES (@BusinessEntityID, @RateChangeDate, @Rate, @PayFrequency);
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END;
| |
| AdventureWorks2025.HumanResources.uspUpdateEmployeeLogin | |
CREATE PROCEDURE [HumanResources].[uspUpdateEmployeeLogin]
@BusinessEntityID [int],
@OrganizationNode [hierarchyid],
@LoginID [nvarchar](256),
@JobTitle [nvarchar](50),
@HireDate [datetime],
@CurrentFlag [dbo].[Flag]
WITH EXECUTE AS CALLER
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
UPDATE [HumanResources].[Employee]
SET [OrganizationNode] = @OrganizationNode
,[LoginID] = @LoginID
,[JobTitle] = @JobTitle
,[HireDate] = @HireDate
,[CurrentFlag] = @CurrentFlag
WHERE [BusinessEntityID] = @BusinessEntityID;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspLogError];
END CATCH;
END;
| |
| AdventureWorks2025.HumanResources.uspUpdateEmployeePersonalInfo | |
CREATE PROCEDURE [HumanResources].[uspUpdateEmployeePersonalInfo]
@BusinessEntityID [int],
@NationalIDNumber [nvarchar](15),
@BirthDate [datetime],
@MaritalStatus [nchar](1),
@Gender [nchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
UPDATE [HumanResources].[Employee]
SET [NationalIDNumber] = @NationalIDNumber
,[BirthDate] = @BirthDate
,[MaritalStatus] = @MaritalStatus
,[Gender] = @Gender
WHERE [BusinessEntityID] = @BusinessEntityID;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspLogError];
END CATCH;
END;
|
| AdventureWorks2025.dbo.fn_diagramobjects | |
CREATE FUNCTION dbo.fn_diagramobjects() RETURNS int WITH EXECUTE AS N'dbo' AS BEGIN declare @id_upgraddiagrams int declare @id_sysdiagrams int declare @id_helpdiagrams int declare @id_helpdiagramdefinition int declare @id_creatediagram int declare @id_renamediagram int declare @id_alterdiagram int declare @id_dropdiagram int declare @InstalledObjects int select @InstalledObjects = 0 select @id_upgraddiagrams = object_id(N'dbo.sp_upgraddiagrams'), @id_sysdiagrams = object_id(N'dbo.sysdiagrams'), @id_helpdiagrams = object_id(N'dbo.sp_helpdiagrams'), @id_helpdiagramdefinition = object_id(N'dbo.sp_helpdiagramdefinition'), @id_creatediagram = object_id(N'dbo.sp_creatediagram'), @id_renamediagram = object_id(N'dbo.sp_renamediagram'), @id_alterdiagram = object_id(N'dbo.sp_alterdiagram'), @id_dropdiagram = object_id(N'dbo.sp_dropdiagram') if @id_upgraddiagrams is not null select @InstalledObjects = @InstalledObjects + 1 if @id_sysdiagrams is not null select @InstalledObjects = @InstalledObjects + 2 if @id_helpdiagrams is not null select @InstalledObjects = @InstalledObjects + 4 if @id_helpdiagramdefinition is not null select @InstalledObjects = @InstalledObjects + 8 if @id_creatediagram is not null select @InstalledObjects = @InstalledObjects + 16 if @id_renamediagram is not null select @InstalledObjects = @InstalledObjects + 32 if @id_alterdiagram is not null select @InstalledObjects = @InstalledObjects + 64 if @id_dropdiagram is not null select @InstalledObjects = @InstalledObjects + 128 return @InstalledObjects END | |
| AdventureWorks2025.dbo.ufnGetAccountingEndDate | |
CREATE FUNCTION [dbo].[ufnGetAccountingEndDate]()
RETURNS [datetime]
AS
BEGIN
RETURN DATEADD(millisecond, -2, CONVERT(datetime, '20040701', 112));
END;
| |
| AdventureWorks2025.dbo.ufnGetAccountingStartDate | |
CREATE FUNCTION [dbo].[ufnGetAccountingStartDate]()
RETURNS [datetime]
AS
BEGIN
RETURN CONVERT(datetime, '20030701', 112);
END;
| |
| AdventureWorks2025.dbo.ufnGetContactInformation | |
CREATE FUNCTION [dbo].[ufnGetContactInformation](@PersonID int)
RETURNS @retContactInformation TABLE
(
-- Columns returned by the function
[PersonID] int NOT NULL,
[FirstName] [nvarchar](50) NULL,
[LastName] [nvarchar](50) NULL,
[JobTitle] [nvarchar](50) NULL,
[BusinessEntityType] [nvarchar](50) NULL
)
AS
-- Returns the first name, last name, job title and business entity type for the specified contact.
-- Since a contact can serve multiple roles, more than one row may be returned.
BEGIN
IF @PersonID IS NOT NULL
BEGIN
IF EXISTS(SELECT * FROM [HumanResources].[Employee] e
WHERE e.[BusinessEntityID] = @PersonID)
INSERT INTO @retContactInformation
SELECT @PersonID, p.FirstName, p.LastName, e.[JobTitle], 'Employee'
FROM [HumanResources].[Employee] AS e
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
WHERE e.[BusinessEntityID] = @PersonID;
IF EXISTS(SELECT * FROM [Purchasing].[Vendor] AS v
INNER JOIN [Person].[BusinessEntityContact] bec
ON bec.[BusinessEntityID] = v.[BusinessEntityID]
WHERE bec.[PersonID] = @PersonID)
INSERT INTO @retContactInformation
SELECT @PersonID, p.FirstName, p.LastName, ct.[Name], 'Vendor Contact'
FROM [Purchasing].[Vendor] AS v
INNER JOIN [Person].[BusinessEntityContact] bec
ON bec.[BusinessEntityID] = v.[BusinessEntityID]
INNER JOIN [Person].ContactType ct
ON ct.[ContactTypeID] = bec.[ContactTypeID]
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = bec.[PersonID]
WHERE bec.[PersonID] = @PersonID;
IF EXISTS(SELECT * FROM [Sales].[Store] AS s
INNER JOIN [Person].[BusinessEntityContact] bec
ON bec.[BusinessEntityID] = s.[BusinessEntityID]
WHERE bec.[PersonID] = @PersonID)
INSERT INTO @retContactInformation
SELECT @PersonID, p.FirstName, p.LastName, ct.[Name], 'Store Contact'
FROM [Sales].[Store] AS s
INNER JOIN [Person].[BusinessEntityContact] bec
ON bec.[BusinessEntityID] = s.[BusinessEntityID]
INNER JOIN [Person].ContactType ct
ON ct.[ContactTypeID] = bec.[ContactTypeID]
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = bec.[PersonID]
WHERE bec.[PersonID] = @PersonID;
IF EXISTS(SELECT * FROM [Person].[Person] AS p
INNER JOIN [Sales].[Customer] AS c
ON c.[PersonID] = p.[BusinessEntityID]
WHERE p.[BusinessEntityID] = @PersonID AND c.[StoreID] IS NULL)
INSERT INTO @retContactInformation
SELECT @PersonID, p.FirstName, p.LastName, NULL, 'Consumer'
FROM [Person].[Person] AS p
INNER JOIN [Sales].[Customer] AS c
ON c.[PersonID] = p.[BusinessEntityID]
WHERE p.[BusinessEntityID] = @PersonID AND c.[StoreID] IS NULL;
END
RETURN;
END;
| |
| AdventureWorks2025.dbo.ufnGetDocumentStatusText | |
CREATE FUNCTION [dbo].[ufnGetDocumentStatusText](@Status [tinyint])
RETURNS [nvarchar](16)
AS
-- Returns the sales order status text representation for the status value.
BEGIN
DECLARE @ret [nvarchar](16);
SET @ret =
CASE @Status
WHEN 1 THEN N'Pending approval'
WHEN 2 THEN N'Approved'
WHEN 3 THEN N'Obsolete'
ELSE N'** Invalid **'
END;
RETURN @ret
END;
| |
| AdventureWorks2025.dbo.ufnGetProductDealerPrice | |
CREATE FUNCTION [dbo].[ufnGetProductDealerPrice](@ProductID [int], @OrderDate [datetime])
RETURNS [money]
AS
-- Returns the dealer price for the product on a specific date.
BEGIN
DECLARE @DealerPrice money;
DECLARE @DealerDiscount money;
SET @DealerDiscount = 0.60 -- 60% of list price
SELECT @DealerPrice = plph.[ListPrice] * @DealerDiscount
FROM [Production].[Product] p
INNER JOIN [Production].[ProductListPriceHistory] plph
ON p.[ProductID] = plph.[ProductID]
AND p.[ProductID] = @ProductID
AND @OrderDate BETWEEN plph.[StartDate] AND COALESCE(plph.[EndDate], CONVERT(datetime, '99991231', 112)); -- Make sure we get all the prices!
RETURN @DealerPrice;
END;
| |
| AdventureWorks2025.dbo.ufnGetProductListPrice | |
CREATE FUNCTION [dbo].[ufnGetProductListPrice](@ProductID [int], @OrderDate [datetime])
RETURNS [money]
AS
BEGIN
DECLARE @ListPrice money;
SELECT @ListPrice = plph.[ListPrice]
FROM [Production].[Product] p
INNER JOIN [Production].[ProductListPriceHistory] plph
ON p.[ProductID] = plph.[ProductID]
AND p.[ProductID] = @ProductID
AND @OrderDate BETWEEN plph.[StartDate] AND COALESCE(plph.[EndDate], CONVERT(datetime, '99991231', 112)); -- Make sure we get all the prices!
RETURN @ListPrice;
END;
| |
| AdventureWorks2025.dbo.ufnGetProductStandardCost | |
CREATE FUNCTION [dbo].[ufnGetProductStandardCost](@ProductID [int], @OrderDate [datetime])
RETURNS [money]
AS
-- Returns the standard cost for the product on a specific date.
BEGIN
DECLARE @StandardCost money;
SELECT @StandardCost = pch.[StandardCost]
FROM [Production].[Product] p
INNER JOIN [Production].[ProductCostHistory] pch
ON p.[ProductID] = pch.[ProductID]
AND p.[ProductID] = @ProductID
AND @OrderDate BETWEEN pch.[StartDate] AND COALESCE(pch.[EndDate], CONVERT(datetime, '99991231', 112)); -- Make sure we get all the prices!
RETURN @StandardCost;
END;
| |
| AdventureWorks2025.dbo.ufnGetPurchaseOrderStatusText | |
CREATE FUNCTION [dbo].[ufnGetPurchaseOrderStatusText](@Status [tinyint])
RETURNS [nvarchar](15)
AS
-- Returns the sales order status text representation for the status value.
BEGIN
DECLARE @ret [nvarchar](15);
SET @ret =
CASE @Status
WHEN 1 THEN 'Pending'
WHEN 2 THEN 'Approved'
WHEN 3 THEN 'Rejected'
WHEN 4 THEN 'Complete'
ELSE '** Invalid **'
END;
RETURN @ret
END;
| |
| AdventureWorks2025.dbo.ufnGetSalesOrderStatusText | |
CREATE FUNCTION [dbo].[ufnGetSalesOrderStatusText](@Status [tinyint])
RETURNS [nvarchar](15)
AS
-- Returns the sales order status text representation for the status value.
BEGIN
DECLARE @ret [nvarchar](15);
SET @ret =
CASE @Status
WHEN 1 THEN 'In process'
WHEN 2 THEN 'Approved'
WHEN 3 THEN 'Backordered'
WHEN 4 THEN 'Rejected'
WHEN 5 THEN 'Shipped'
WHEN 6 THEN 'Cancelled'
ELSE '** Invalid **'
END;
RETURN @ret
END;
| |
| AdventureWorks2025.dbo.ufnGetStock | |
CREATE FUNCTION [dbo].[ufnGetStock](@ProductID [int])
RETURNS [int]
AS
-- Returns the stock level for the product. This function is used internally only
BEGIN
DECLARE @ret int;
SELECT @ret = SUM(p.[Quantity])
FROM [Production].[ProductInventory] p
WHERE p.[ProductID] = @ProductID
AND p.[LocationID] = '6'; -- Only look at inventory in the misc storage
IF (@ret IS NULL)
SET @ret = 0
RETURN @ret
END;
| |
| AdventureWorks2025.dbo.ufnLeadingZeros | |
CREATE FUNCTION [dbo].[ufnLeadingZeros](
@Value int
)
RETURNS varchar(8)
WITH SCHEMABINDING
AS
BEGIN
DECLARE @ReturnValue varchar(8);
SET @ReturnValue = CONVERT(varchar(8), @Value);
SET @ReturnValue = REPLICATE('0', 8 - DATALENGTH(@ReturnValue)) + @ReturnValue;
RETURN (@ReturnValue);
END;
|
| AdventureWorks2025.dbo.sp_alterdiagram | |
CREATE PROCEDURE dbo.sp_alterdiagram
(
@diagramname sysname,
@owner_id int = null,
@version int,
@definition varbinary(max)
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
set nocount on
declare @theId int
declare @retval int
declare @IsDbo int
declare @UIDFound int
declare @DiagId int
declare @ShouldChangeUID int
if(@diagramname is null)
begin
RAISERROR ('Invalid ARG', 16, 1)
return -1
end
execute as caller;
select @theId = DATABASE_PRINCIPAL_ID();
select @IsDbo = IS_MEMBER(N'db_owner');
if(@owner_id is null)
select @owner_id = @theId;
revert;
select @ShouldChangeUID = 0
select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname
if(@DiagId IS NULL or (@IsDbo = 0 and @theId <> @UIDFound))
begin
RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1);
return -3
end
if(@IsDbo <> 0)
begin
if(@UIDFound is null or USER_NAME(@UIDFound) is null) -- invalid principal_id
begin
select @ShouldChangeUID = 1 ;
end
end
-- update dds data
update dbo.sysdiagrams set definition = @definition where diagram_id = @DiagId ;
-- change owner
if(@ShouldChangeUID = 1)
update dbo.sysdiagrams set principal_id = @theId where diagram_id = @DiagId ;
-- update dds version
if(@version is not null)
update dbo.sysdiagrams set version = @version where diagram_id = @DiagId ;
return 0
END
| |
| AdventureWorks2025.dbo.sp_creatediagram | |
CREATE PROCEDURE dbo.sp_creatediagram
(
@diagramname sysname,
@owner_id int = null,
@version int,
@definition varbinary(max)
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
set nocount on
declare @theId int
declare @retval int
declare @IsDbo int
declare @userName sysname
if(@version is null or @diagramname is null)
begin
RAISERROR (N'E_INVALIDARG', 16, 1);
return -1
end
execute as caller;
select @theId = DATABASE_PRINCIPAL_ID();
select @IsDbo = IS_MEMBER(N'db_owner');
revert;
if @owner_id is null
begin
select @owner_id = @theId;
end
else
begin
if @theId <> @owner_id
begin
if @IsDbo = 0
begin
RAISERROR (N'E_INVALIDARG', 16, 1);
return -1
end
select @theId = @owner_id
end
end
-- next 2 line only for test, will be removed after define name unique
if EXISTS(select diagram_id from dbo.sysdiagrams where principal_id = @theId and name = @diagramname)
begin
RAISERROR ('The name is already used.', 16, 1);
return -2
end
insert into dbo.sysdiagrams(name, principal_id , version, definition)
VALUES(@diagramname, @theId, @version, @definition) ;
select @retval = @@IDENTITY
return @retval
END
| |
| AdventureWorks2025.dbo.sp_dropdiagram | |
CREATE PROCEDURE dbo.sp_dropdiagram
(
@diagramname sysname,
@owner_id int = null
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
set nocount on
declare @theId int
declare @IsDbo int
declare @UIDFound int
declare @DiagId int
if(@diagramname is null)
begin
RAISERROR ('Invalid value', 16, 1);
return -1
end
EXECUTE AS CALLER;
select @theId = DATABASE_PRINCIPAL_ID();
select @IsDbo = IS_MEMBER(N'db_owner');
if(@owner_id is null)
select @owner_id = @theId;
REVERT;
select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname
if(@DiagId IS NULL or (@IsDbo = 0 and @UIDFound <> @theId))
begin
RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1)
return -3
end
delete from dbo.sysdiagrams where diagram_id = @DiagId;
return 0;
END
| |
| AdventureWorks2025.dbo.sp_helpdiagramdefinition | |
CREATE PROCEDURE dbo.sp_helpdiagramdefinition
(
@diagramname sysname,
@owner_id int = null
)
WITH EXECUTE AS N'dbo'
AS
BEGIN
set nocount on
declare @theId int
declare @IsDbo int
declare @DiagId int
declare @UIDFound int
if(@diagramname is null)
begin
RAISERROR (N'E_INVALIDARG', 16, 1);
return -1
end
execute as caller;
select @theId = DATABASE_PRINCIPAL_ID();
select @IsDbo = IS_MEMBER(N'db_owner');
if(@owner_id is null)
select @owner_id = @theId;
revert;
select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname;
if(@DiagId IS NULL or (@IsDbo = 0 and @UIDFound <> @theId ))
begin
RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1);
return -3
end
select version, definition FROM dbo.sysdiagrams where diagram_id = @DiagId ;
return 0
END
| |
| AdventureWorks2025.dbo.sp_helpdiagrams | |
CREATE PROCEDURE dbo.sp_helpdiagrams
(
@diagramname sysname = NULL,
@owner_id int = NULL
)
WITH EXECUTE AS N'dbo'
AS
BEGIN
DECLARE @user sysname
DECLARE @dboLogin bit
EXECUTE AS CALLER;
SET @user = USER_NAME();
SET @dboLogin = CONVERT(bit,IS_MEMBER('db_owner'));
REVERT;
SELECT
[Database] = DB_NAME(),
[Name] = name,
[ID] = diagram_id,
[Owner] = USER_NAME(principal_id),
[OwnerID] = principal_id
FROM
sysdiagrams
WHERE
(@dboLogin = 1 OR USER_NAME(principal_id) = @user) AND
(@diagramname IS NULL OR name = @diagramname) AND
(@owner_id IS NULL OR principal_id = @owner_id)
ORDER BY
4, 5, 1
END
| |
| AdventureWorks2025.dbo.sp_renamediagram | |
CREATE PROCEDURE dbo.sp_renamediagram
(
@diagramname sysname,
@owner_id int = null,
@new_diagramname sysname
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
set nocount on
declare @theId int
declare @IsDbo int
declare @UIDFound int
declare @DiagId int
declare @DiagIdTarg int
declare @u_name sysname
if((@diagramname is null) or (@new_diagramname is null))
begin
RAISERROR ('Invalid value', 16, 1);
return -1
end
EXECUTE AS CALLER;
select @theId = DATABASE_PRINCIPAL_ID();
select @IsDbo = IS_MEMBER(N'db_owner');
if(@owner_id is null)
select @owner_id = @theId;
REVERT;
select @u_name = USER_NAME(@owner_id)
select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname
if(@DiagId IS NULL or (@IsDbo = 0 and @UIDFound <> @theId))
begin
RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1)
return -3
end
-- if((@u_name is not null) and (@new_diagramname = @diagramname)) -- nothing will change
-- return 0;
if(@u_name is null)
select @DiagIdTarg = diagram_id from dbo.sysdiagrams where principal_id = @theId and name = @new_diagramname
else
select @DiagIdTarg = diagram_id from dbo.sysdiagrams where principal_id = @owner_id and name = @new_diagramname
if((@DiagIdTarg is not null) and @DiagId <> @DiagIdTarg)
begin
RAISERROR ('The name is already used.', 16, 1);
return -2
end
if(@u_name is null)
update dbo.sysdiagrams set [name] = @new_diagramname, principal_id = @theId where diagram_id = @DiagId
else
update dbo.sysdiagrams set [name] = @new_diagramname where diagram_id = @DiagId
return 0
END
| |
| AdventureWorks2025.dbo.sp_upgraddiagrams | |
CREATE PROCEDURE dbo.sp_upgraddiagrams AS BEGIN IF OBJECT_ID(N'dbo.sysdiagrams') IS NOT NULL return 0; CREATE TABLE dbo.sysdiagrams ( name sysname NOT NULL, principal_id int NOT NULL, -- we may change it to varbinary(85) diagram_id int PRIMARY KEY IDENTITY, version int, definition varbinary(max) CONSTRAINT UK_principal_name UNIQUE ( principal_id, name ) ); /* Add this if we need to have some form of extended properties for diagrams */ /* IF OBJECT_ID(N'dbo.sysdiagram_properties') IS NULL BEGIN CREATE TABLE dbo.sysdiagram_properties ( diagram_id int, name sysname, value varbinary(max) NOT NULL ) END */ IF OBJECT_ID(N'dbo.dtproperties') IS NOT NULL begin insert into dbo.sysdiagrams ( [name], [principal_id], [version], [definition] ) select convert(sysname, dgnm.[uvalue]), DATABASE_PRINCIPAL_ID(N'dbo'), -- will change to the sid of sa 0, -- zero for old format, dgdef.[version], dgdef.[lvalue] from dbo.[dtproperties] dgnm inner join dbo.[dtproperties] dggd on dggd.[property] = 'DtgSchemaGUID' and dggd.[objectid] = dgnm.[objectid] inner join dbo.[dtproperties] dgdef on dgdef.[property] = 'DtgSchemaDATA' and dgdef.[objectid] = dgnm.[objectid] where dgnm.[property] = 'DtgSchemaNAME' and dggd.[uvalue] like N'_EA3E6268-D998-11CE-9454-00AA00A3F36E_' return 2; end return 1; END | |
| AdventureWorks2025.dbo.uspGetBillOfMaterials | |
CREATE PROCEDURE [dbo].[uspGetBillOfMaterials]
@StartProductID [int],
@CheckDate [datetime]
AS
BEGIN
SET NOCOUNT ON;
-- Use recursive query to generate a multi-level Bill of Material (i.e. all level 1
-- components of a level 0 assembly, all level 2 components of a level 1 assembly)
-- The CheckDate eliminates any components that are no longer used in the product on this date.
WITH [BOM_cte]([ProductAssemblyID], [ComponentID], [ComponentDesc], [PerAssemblyQty], [StandardCost], [ListPrice], [BOMLevel], [RecursionLevel]) -- CTE name and columns
AS (
SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], 0 -- Get the initial list of components for the bike assembly
FROM [Production].[BillOfMaterials] b
INNER JOIN [Production].[Product] p
ON b.[ComponentID] = p.[ProductID]
WHERE b.[ProductAssemblyID] = @StartProductID
AND @CheckDate >= b.[StartDate]
AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate)
UNION ALL
SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], [RecursionLevel] + 1 -- Join recursive member to anchor
FROM [BOM_cte] cte
INNER JOIN [Production].[BillOfMaterials] b
ON b.[ProductAssemblyID] = cte.[ComponentID]
INNER JOIN [Production].[Product] p
ON b.[ComponentID] = p.[ProductID]
WHERE @CheckDate >= b.[StartDate]
AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate)
)
-- Outer select from the CTE
SELECT b.[ProductAssemblyID], b.[ComponentID], b.[ComponentDesc], SUM(b.[PerAssemblyQty]) AS [TotalQuantity] , b.[StandardCost], b.[ListPrice], b.[BOMLevel], b.[RecursionLevel]
FROM [BOM_cte] b
GROUP BY b.[ComponentID], b.[ComponentDesc], b.[ProductAssemblyID], b.[BOMLevel], b.[RecursionLevel], b.[StandardCost], b.[ListPrice]
ORDER BY b.[BOMLevel], b.[ProductAssemblyID], b.[ComponentID]
OPTION (MAXRECURSION 25)
END;
| |
| AdventureWorks2025.dbo.uspGetEmployeeManagers | |
CREATE PROCEDURE [dbo].[uspGetEmployeeManagers]
@BusinessEntityID [int]
AS
BEGIN
SET NOCOUNT ON;
-- Use recursive query to list out all Employees required for a particular Manager
WITH [EMP_cte]([BusinessEntityID], [OrganizationNode], [FirstName], [LastName], [JobTitle], [RecursionLevel]) -- CTE name and columns
AS (
SELECT e.[BusinessEntityID], e.[OrganizationNode], p.[FirstName], p.[LastName], e.[JobTitle], 0 -- Get the initial Employee
FROM [HumanResources].[Employee] e
INNER JOIN [Person].[Person] as p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
WHERE e.[BusinessEntityID] = @BusinessEntityID
UNION ALL
SELECT e.[BusinessEntityID], e.[OrganizationNode], p.[FirstName], p.[LastName], e.[JobTitle], [RecursionLevel] + 1 -- Join recursive member to anchor
FROM [HumanResources].[Employee] e
INNER JOIN [EMP_cte]
ON e.[OrganizationNode] = [EMP_cte].[OrganizationNode].GetAncestor(1)
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
)
-- Join back to Employee to return the manager name
SELECT [EMP_cte].[RecursionLevel], [EMP_cte].[BusinessEntityID], [EMP_cte].[FirstName], [EMP_cte].[LastName],
[EMP_cte].[OrganizationNode].ToString() AS [OrganizationNode], p.[FirstName] AS 'ManagerFirstName', p.[LastName] AS 'ManagerLastName' -- Outer select from the CTE
FROM [EMP_cte]
INNER JOIN [HumanResources].[Employee] e
ON [EMP_cte].[OrganizationNode].GetAncestor(1) = e.[OrganizationNode]
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
ORDER BY [RecursionLevel], [EMP_cte].[OrganizationNode].ToString()
OPTION (MAXRECURSION 25)
END;
| |
| AdventureWorks2025.dbo.uspGetManagerEmployees | |
CREATE PROCEDURE [dbo].[uspGetManagerEmployees]
@BusinessEntityID [int]
AS
BEGIN
SET NOCOUNT ON;
-- Use recursive query to list out all Employees required for a particular Manager
WITH [EMP_cte]([BusinessEntityID], [OrganizationNode], [FirstName], [LastName], [RecursionLevel]) -- CTE name and columns
AS (
SELECT e.[BusinessEntityID], e.[OrganizationNode], p.[FirstName], p.[LastName], 0 -- Get the initial list of Employees for Manager n
FROM [HumanResources].[Employee] e
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
WHERE e.[BusinessEntityID] = @BusinessEntityID
UNION ALL
SELECT e.[BusinessEntityID], e.[OrganizationNode], p.[FirstName], p.[LastName], [RecursionLevel] + 1 -- Join recursive member to anchor
FROM [HumanResources].[Employee] e
INNER JOIN [EMP_cte]
ON e.[OrganizationNode].GetAncestor(1) = [EMP_cte].[OrganizationNode]
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
)
-- Join back to Employee to return the manager name
SELECT [EMP_cte].[RecursionLevel], [EMP_cte].[OrganizationNode].ToString() as [OrganizationNode], p.[FirstName] AS 'ManagerFirstName', p.[LastName] AS 'ManagerLastName',
[EMP_cte].[BusinessEntityID], [EMP_cte].[FirstName], [EMP_cte].[LastName] -- Outer select from the CTE
FROM [EMP_cte]
INNER JOIN [HumanResources].[Employee] e
ON [EMP_cte].[OrganizationNode].GetAncestor(1) = e.[OrganizationNode]
INNER JOIN [Person].[Person] p
ON p.[BusinessEntityID] = e.[BusinessEntityID]
ORDER BY [RecursionLevel], [EMP_cte].[OrganizationNode].ToString()
OPTION (MAXRECURSION 25)
END;
| |
| AdventureWorks2025.dbo.uspGetWhereUsedProductID | |
CREATE PROCEDURE [dbo].[uspGetWhereUsedProductID]
@StartProductID [int],
@CheckDate [datetime]
AS
BEGIN
SET NOCOUNT ON;
--Use recursive query to generate a multi-level Bill of Material (i.e. all level 1 components of a level 0 assembly, all level 2 components of a level 1 assembly)
WITH [BOM_cte]([ProductAssemblyID], [ComponentID], [ComponentDesc], [PerAssemblyQty], [StandardCost], [ListPrice], [BOMLevel], [RecursionLevel]) -- CTE name and columns
AS (
SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], 0 -- Get the initial list of components for the bike assembly
FROM [Production].[BillOfMaterials] b
INNER JOIN [Production].[Product] p
ON b.[ProductAssemblyID] = p.[ProductID]
WHERE b.[ComponentID] = @StartProductID
AND @CheckDate >= b.[StartDate]
AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate)
UNION ALL
SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], [RecursionLevel] + 1 -- Join recursive member to anchor
FROM [BOM_cte] cte
INNER JOIN [Production].[BillOfMaterials] b
ON cte.[ProductAssemblyID] = b.[ComponentID]
INNER JOIN [Production].[Product] p
ON b.[ProductAssemblyID] = p.[ProductID]
WHERE @CheckDate >= b.[StartDate]
AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate)
)
-- Outer select from the CTE
SELECT b.[ProductAssemblyID], b.[ComponentID], b.[ComponentDesc], SUM(b.[PerAssemblyQty]) AS [TotalQuantity] , b.[StandardCost], b.[ListPrice], b.[BOMLevel], b.[RecursionLevel]
FROM [BOM_cte] b
GROUP BY b.[ComponentID], b.[ComponentDesc], b.[ProductAssemblyID], b.[BOMLevel], b.[RecursionLevel], b.[StandardCost], b.[ListPrice]
ORDER BY b.[BOMLevel], b.[ProductAssemblyID], b.[ComponentID]
OPTION (MAXRECURSION 25)
END;
| |
| AdventureWorks2025.dbo.uspLogError | |
-- uspLogError logs error information in the ErrorLog table about the
-- error that caused execution to jump to the CATCH block of a
-- TRY...CATCH construct. This should be executed from within the scope
-- of a CATCH block otherwise it will return without inserting error
-- information.
CREATE PROCEDURE [dbo].[uspLogError]
@ErrorLogID [int] = 0 OUTPUT -- contains the ErrorLogID of the row inserted
AS -- by uspLogError in the ErrorLog table
BEGIN
SET NOCOUNT ON;
-- Output parameter value of 0 indicates that error
-- information was not logged
SET @ErrorLogID = 0;
BEGIN TRY
-- Return if there is no error information to log
IF ERROR_NUMBER() IS NULL
RETURN;
-- Return if inside an uncommittable transaction.
-- Data insertion/modification is not allowed when
-- a transaction is in an uncommittable state.
IF XACT_STATE() = -1
BEGIN
PRINT 'Cannot log error since the current transaction is in an uncommittable state. '
+ 'Rollback the transaction before executing uspLogError in order to successfully log error information.';
RETURN;
END
INSERT [dbo].[ErrorLog]
(
[UserName],
[ErrorNumber],
[ErrorSeverity],
[ErrorState],
[ErrorProcedure],
[ErrorLine],
[ErrorMessage]
)
VALUES
(
CONVERT(sysname, CURRENT_USER),
ERROR_NUMBER(),
ERROR_SEVERITY(),
ERROR_STATE(),
ERROR_PROCEDURE(),
ERROR_LINE(),
ERROR_MESSAGE()
);
-- Pass back the ErrorLogID of the row inserted
SET @ErrorLogID = @@IDENTITY;
END TRY
BEGIN CATCH
PRINT 'An error occurred in stored procedure uspLogError: ';
EXECUTE [dbo].[uspPrintError];
RETURN -1;
END CATCH
END;
| |
| AdventureWorks2025.dbo.uspPrintError | |
-- uspPrintError prints 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.
CREATE PROCEDURE [dbo].[uspPrintError]
AS
BEGIN
SET NOCOUNT ON;
-- Print error information.
PRINT 'Error ' + CONVERT(varchar(50), ERROR_NUMBER()) +
', Severity ' + CONVERT(varchar(5), ERROR_SEVERITY()) +
', State ' + CONVERT(varchar(5), ERROR_STATE()) +
', Procedure ' + ISNULL(ERROR_PROCEDURE(), '-') +
', Line ' + CONVERT(varchar(5), ERROR_LINE());
PRINT ERROR_MESSAGE();
END;
| |
| AdventureWorks2025.dbo.uspSearchCandidateResumes | |
--A stored procedure which demonstrates integrated full text search
CREATE PROCEDURE [dbo].[uspSearchCandidateResumes]
@searchString [nvarchar](1000),
@useInflectional [bit]=0,
@useThesaurus [bit]=0,
@language[int]=0
WITH EXECUTE AS CALLER
AS
BEGIN
SET NOCOUNT ON;
DECLARE @string nvarchar(1050)
--setting the lcid to the default instance LCID if needed
IF @language = NULL OR @language = 0
BEGIN
SELECT @language =CONVERT(int, serverproperty('lcid'))
END
--FREETEXTTABLE case as inflectional and Thesaurus were required
IF @useThesaurus = 1 AND @useInflectional = 1
BEGIN
SELECT FT_TBL.[JobCandidateID], KEY_TBL.[RANK] FROM [HumanResources].[JobCandidate] AS FT_TBL
INNER JOIN FREETEXTTABLE([HumanResources].[JobCandidate],*, @searchString,LANGUAGE @language) AS KEY_TBL
ON FT_TBL.[JobCandidateID] =KEY_TBL.[KEY]
END
ELSE IF @useThesaurus = 1
BEGIN
SELECT @string = 'FORMSOF(THESAURUS,"'+@searchString +'"'+')'
SELECT FT_TBL.[JobCandidateID], KEY_TBL.[RANK] FROM [HumanResources].[JobCandidate] AS FT_TBL
INNER JOIN CONTAINSTABLE([HumanResources].[JobCandidate],*, @string,LANGUAGE @language) AS KEY_TBL
ON FT_TBL.[JobCandidateID] =KEY_TBL.[KEY]
END
ELSE IF @useInflectional = 1
BEGIN
SELECT @string = 'FORMSOF(INFLECTIONAL,"'+@searchString +'"'+')'
SELECT FT_TBL.[JobCandidateID], KEY_TBL.[RANK] FROM [HumanResources].[JobCandidate] AS FT_TBL
INNER JOIN CONTAINSTABLE([HumanResources].[JobCandidate],*, @string,LANGUAGE @language) AS KEY_TBL
ON FT_TBL.[JobCandidateID] =KEY_TBL.[KEY]
END
ELSE --base case, plain CONTAINSTABLE
BEGIN
SELECT @string = '"'+@searchString +'"'
SELECT FT_TBL.[JobCandidateID],KEY_TBL.[RANK] FROM [HumanResources].[JobCandidate] AS FT_TBL
INNER JOIN CONTAINSTABLE([HumanResources].[JobCandidate],*,@string,LANGUAGE @language) AS KEY_TBL
ON FT_TBL.[JobCandidateID] =KEY_TBL.[KEY]
END
END;
|
| User Data Types | Description |
|---|---|
| AccountNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Flag | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| Name | |
CREATE TYPE ${name} FROM nvarchar | |
| NameStyle | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| OrderNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Phone | |
CREATE TYPE ${name} FROM nvarchar |
| User Data Types | Description |
|---|---|
| AccountNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Flag | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| Name | |
CREATE TYPE ${name} FROM nvarchar | |
| NameStyle | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| OrderNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Phone | |
CREATE TYPE ${name} FROM nvarchar |
| User Data Types | Description |
|---|---|
| AccountNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Flag | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| Name | |
CREATE TYPE ${name} FROM nvarchar | |
| NameStyle | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| OrderNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Phone | |
CREATE TYPE ${name} FROM nvarchar |
| User Data Types | Description |
|---|---|
| AccountNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Flag | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| Name | |
CREATE TYPE ${name} FROM nvarchar | |
| NameStyle | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| OrderNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Phone | |
CREATE TYPE ${name} FROM nvarchar |
| User Data Types | Description |
|---|---|
| AccountNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Flag | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| Name | |
CREATE TYPE ${name} FROM nvarchar | |
| NameStyle | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| OrderNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Phone | |
CREATE TYPE ${name} FROM nvarchar |
| User Data Types | Description |
|---|---|
| AccountNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Flag | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| Name | |
CREATE TYPE ${name} FROM nvarchar | |
| NameStyle | |
CREATE TYPE ${name} FROM bit(1) NOT NULL | |
| OrderNumber | |
CREATE TYPE ${name} FROM nvarchar | |
| Phone | |
CREATE TYPE ${name} FROM nvarchar |