AdventureWorks LT database: schema, tables and SQL exercises
AdventureWorks LT is the Microsoft SQL Server sample database of a bicycle manufacturer: customers, products, product categories and sales orders. On SQLtest.online you can query it right in your browser: solve exercises with automatic checking and run your own queries in the playground, with nothing to install.
- 10 main tables
- 847 customers
- 295 products
- 34 SQL exercises
What is AdventureWorks
AdventureWorks is the sample database Microsoft ships for SQL Server and Azure SQL. It describes Adventure Works Cycles, a fictional company that makes and sells bicycles, parts and accessories.
The site uses AdventureWorks LT, the lightweight edition: the same business in about ten tables instead of dozens. It is a good place to practice T-SQL, including TOP, self-joins on a category tree and many-to-many relationships.
ER diagram
The diagram shows the AdventureWorks tables and the foreign keys between them. Click it to open the full-size version.
What's inside
The tables fall into three groups.
Customers
Customer, Address and the link table CustomerAddress, which also stores the address type.
Products
Product, ProductCategory (a tree: each category can have a parent), ProductModel and descriptions in several languages.
Sales
SalesOrderHeader holds the orders, SalesOrderDetail their lines.
All 32 orders in this edition are dated 1 June 2008. Product descriptions are linked to models through ProductModelProductDescription, which also stores the language (culture) of each description. The service tables BuildVersion, ErrorLog and sysdiagrams are not used in the exercises.
How much data the tables hold:
| Table | Rows | Contents |
|---|---|---|
| Customer | 847 | customers |
| CustomerAddress | 417 | customer ↔ address links |
| Address | 450 | addresses |
| SalesOrderHeader | 32 | orders |
| SalesOrderDetail | 542 | order lines |
| Product | 295 | products |
| ProductCategory | 41 | product categories |
| ProductModel | 128 | product models |
| ProductDescription | 762 | product descriptions |
| ProductModelProductDescription | 762 | model ↔ description links by language |
Table structure
Click a table to see its columns, a sample row and its keys.
List of tables
- AddressIDunique identifier for each address (PK)
- AddressLine1the first line of the address
- AddressLine2the second line of the address
- Citycity
- StateProvincestate or province
- CountryRegioncountry
- PostalCodepostal code
- rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (AddressID)
| AddressID | AddressLine1 | AddressLine2 | City | StateProvince | CountryRegion | PostalCode | rowguid | ModifiedDate |
|---|---|---|---|---|---|---|---|---|
| 9 | 8713 Yosemite Ct. | null | Bothell | Washington | United States | 98011 | 268AF621-76D7-4C78-9441-144FD139821A | 2006-07-01 00:00:00.000 |
- CustomerIDunique identifier for each customer (PK)
- NameStyle0 = The data in FirstName and LastName are stored in western style (first name, last name) order. 1 = Eastern style (last name, first name) order. Default: 0
- Titletitle
- FirstNamename
- MiddleNamemiddle name
- LastNamelast name
- Suffixsuffix
- CompanyNamecompany name
- SalesPersonSalesPerson
- EmailAddressE-mail
- Phonephone number
- PasswordHashpassword hash
- PasswordSaltsalt
- rowguidrowguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (CustomerID)
| CustomerID | NameStyle | Title | FirstName | MiddleName | LastName | Suffix | CompanyName | SalesPerson | EmailAddress | Phone | PasswordHash | PasswordSalt | rowguid | ModifiedDate |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | Mr. | Orlando | N. | Gee | [null] | A Bike Store | adventure-works\pamela0 | orlando0@adventure-works.com | 245-555-0173 | L/Rlwxzp4w7RWmEgXX+/A7cXaePEPcp+KwQhl2fJL7w= | 1KjXYs4= | 3F5AE95E-B87D-4AED-95B4-C3797AFCB74F | 2005-08-01 00:00:00.000 |
- CustomerIDidentifier of client in the Customer table
- AddressIDidentifier of address in the Address table
- AddressTypeaddress type
- rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (CustomerID, AddressID)
- FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID)
- FOREIGN KEY (AddressID) REFERENCES Address(AddressID)
| CustomerID | AddressID | AddressType | rowguid | ModifiedDate |
|---|---|---|---|---|
| 29485 | 1086 | Main Office | 16765338-DBE4-4421-B5E9-3836B9278E63 | 2007-09-01 00:00:00.000 |
- ProductIDunique identifier for each product (PK)
- Nameproduct name
- ProductNumberarticle number
- Colorproduct color
- StandardCostproduct price
- ListPriceproduct price in the catalogue
- Sizeproduct size
- Weightproduct weight
- ProductCategoryIDforeign key pointing to ProductCategory table
- ProductModelIDforeign key pointing to ProductModel table
- SellStartDatetimestamp of the sales start date
- SellEndDatetimestamp of the sales end date
- DiscontinuedDatetimestamp of the sales end date
- ThumbNailPhotothumbnail photo of the product
- ThumbnailPhotoFileName
name of the photo thumbnail file - rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (ProductID, ProductCategoryID, ProductModelID)
- FOREIGN KEY (ProductCategoryID) REFERENCES ProductCategory(ProductCategoryID)
- FOREIGN KEY (ProductModelID) REFERENCES ProductModel(ProductModelID)
| ProductID | Name | ProductNumber | Color | StandardCost | ListPrice | Size | Weight | ProductCategoryID | ProductModelID | SellStartDate | SellEndDate | DiscontinuedDate | ThumbNailPhoto | ThumbnailPhotoFileName | rowguid | ModifiedDate |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 680 | HL Road Frame - Black, 58 | FR-R92B-58 | Black | 1059.3100 | 1431.5000 | 58 | 1016.04 | 18 | 6 | 2002-06-01 00:00:00.000 | [null] | [null] | [binary] | no_image_available_small.gif | 43DD68D6-14A4-461F-9069-55309D90EA7E | 2008-03-11 10:01:36.827 |
- ProductCategoryIDunique identifier for each product category (PK)
- ParentProductCategoryIDID of the parent product category
- Namename of the product category
- rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (ProductCategoryID)
- FOREIGN KEY (ParentProductCategoryID) REFERENCES ProductCategory(ProductCategoryID)
| ProductCategoryID | ParentProductCategoryID | Name | rowguid | ModifiedDate |
|---|---|---|---|---|
| 1 | [null] | Bikes | CFBDA25C-DF71-47A7-B81B-64EE161AA37C | 2002-06-01 00:00:00.000 |
- ProductDescriptionIDunique ID for record (PK)
- Descriptionproduct description
- rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (ProductDescriptionID)
| ProductDescriptionID | Description | rowguid | ModifiedDate |
|---|---|---|---|
| 4 | Aluminum alloy cups; large diameter spindle. | DFEBA528-DA11-4650-9D86-CAFDA7294EB0 | 2007-06-01 00:00:00.000 |
- ProductModelIDunique ID for each record (PK)
- Namename of the product model
- CatalogDescriptiondescription in XML format
- rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (ProductModelID)
| ProductModelID | Name | CatalogDescription | rowguid | ModifiedDate |
|---|---|---|---|---|
| 1 | Classic Vest | [null] | 29321D47-1E4C-4AAC-887C-19634328C25E | 2007-06-01 00:00:00.000 |
- ProductModelIDID of client in the ProductModel table
- ProductDescriptionIDID of address in the ProductDescription table
- Culturelanguage code in ISO format
- rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (ProductModelID, ProductDescriptionID)
- FOREIGN KEY (ProductModelID) REFERENCES ProductModel(ProductModelID)
- FOREIGN KEY (ProductDescriptionID) REFERENCES ProductDescription(ProductDescriptionID)
| ProductModelID | ProductDescriptionID | Culture | rowguid | ModifiedDate |
|---|---|---|---|---|
| 1 | 1199 | en | 4D00B649-027A-4F99-A380-F22A46EC8638 | 2007-06-01 00:00:00.000 |
- SalesOrderIDforeign key referencing the SalesOrderHeader table
- SalesOrderDetailIDunique identifier of record in the table
- OrderQtyquantity
- ProductIDa foreign key referencing the Product table
- UnitPriceprice per unit of goods
- UnitPriceDiscountprice per unit of product with a discount
- LineTotaltotal amount by line
- rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (SalesOrderID, SalesOrderDetailID, ProductID)
- FOREIGN KEY (SalesOrderID) REFERENCES SalesOrderHeader(SalesOrderID)
- FOREIGN KEY (ProductID) REFERENCES Product(ProductID)
| SalesOrderID | SalesOrderDetailID | OrderQty | ProductID | UnitPrice | UnitPriceDiscount | LineTotal | rowguid | ModifiedDate |
|---|---|---|---|---|---|---|---|---|
| 71774 | 110562 | 1 | 836 | 356.8980 | .0000 | 356.898000 | E3A1994C-7A68-4CE8-96A3-77FDD3BBD730 | 2008-06-01 00:00:00.000 |
- SalesOrderIDunique identifier of record in the table (PK)
- RevisionNumberrevision number
- OrderDatetimestamp for creating the order date
- DueDatetimestamp of the order payment date
- ShipDatetimestamp of the date the order was shipped
- Statusorder status
- OnlineOrderFlagonline order (yes/no)
- SalesOrderNumberorder number
- PurchaseOrderNumberpurchase number
- AccountNumberaccount number
- CustomerIDforeign key referencing the Customer table
- ShipToAddressIDforeign key referencing the Address table defines the delivery address
- BillToAddressIDforeign key referencing the Address table defines the account address
- ShipMethoddelivery method
- CreditCardApprovalCode
credit card confirmation code - SubTotalsubtotal
- TaxAmttaxes
- Freightdelivery cost
- TotalDuetotal
- Commentcomment
- rowguidguid
- ModifiedDatetimestamp of row creation or last update
- PRIMARY KEY, btree (SalesOrderID, CustomerID, ShipToAddressID, BillToAddressID)
- FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID)
- FOREIGN KEY (ShipToAddressID) REFERENCES Address(AddressID)
- FOREIGN KEY (BillToAddressID) REFERENCES Address(AddressID)
| SalesOrderID | RevisionNumber | OrderDate | DueDate | ShipDate | Status | OnlineOrderFlag | SalesOrderNumber | PurchaseOrderNumber | AccountNumber | CustomerID | ShipToAddressID | BillToAddressID | ShipMethod | CreditCardApprovalCode | SubTotal | TaxAmt | Freight | TotalDue | Comment | rowguid | ModifiedDate |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 71774 | 2 | 2008-06-01 00:00:00.000 | 2008-06-13 00:00:00.000 | 2008-06-08 00:00:00.000 | 5 | 0 | SO71774 | PO348186287 | 10-4020-000609 | 29847 | 1092 | 1092 | CARGO TRANSPORT 5 | [null] | 880.3484 | 70.4279 | 22.0087 | 972.7850 | [null] | 89E42CDC-8506-48A2-B89B-EB3E64E3554E | 2008-06-08 00:00:00.000 |
Sample queries
These queries show how the data is connected. Copy any of them and run it in the playground.
A customer and their addresses: a many-to-many link through CustomerAddress.
SELECT TOP 3 c.FirstName, c.LastName, ca.AddressType, a.City
FROM Customer c
JOIN CustomerAddress ca ON ca.CustomerID = c.CustomerID
JOIN Address a ON a.AddressID = ca.AddressID
ORDER BY c.CustomerID;
| FirstName | LastName | AddressType | City |
|---|---|---|---|
| Catherine | Abel | Main Office | Van Nuys |
| Kim | Abercrombie | Main Office | Branch |
| Frances | Adams | Main Office | Modesto |
An order and its lines: from the order header to the products.
SELECT TOP 3 h.SalesOrderID, h.OrderDate, p.Name, d.OrderQty, d.UnitPrice
FROM SalesOrderHeader h
JOIN SalesOrderDetail d ON d.SalesOrderID = h.SalesOrderID
JOIN Product p ON p.ProductID = d.ProductID
ORDER BY h.SalesOrderID, d.SalesOrderDetailID;
| SalesOrderID | OrderDate | Name | OrderQty | UnitPrice |
|---|---|---|---|---|
| 71774 | 2008-06-01 00:00:00.000 | ML Road Frame-W - Yellow, 48 | 1 | 356.8980 |
| 71774 | 2008-06-01 00:00:00.000 | ML Road Frame-W - Yellow, 38 | 1 | 356.8980 |
| 71776 | 2008-06-01 00:00:00.000 | Rear Brakes | 1 | 63.9000 |
SQL exercises by topic
There are 34 exercises on the AdventureWorks database, from simple filters to analytics on orders and products. Solutions are checked automatically on a real SQL Server. The number on the right is how many exercises a topic has; the colored dots show its difficulty range.
Where to start
The first exercises on the AdventureWorks database:
- Product Categories
- Product List
- Filtered list of products
- Ten heaviest products
- Get list of tables (SQL Server)
- Even-Numbered Customers
- Customers by Phone Prefix
- Duplicate Phone Numbers
- List Unique Customers
- Duplicate Emails
All AdventureWorks exercises →
FAQ
Do I need to install SQL Server to use AdventureWorks?
No. The exercises and the playground on SQLtest.online run your queries on our servers, so a browser is all you need. In the playground, AdventureWorks is available on SQL Server 2022.
How is AdventureWorks LT different from the full AdventureWorks?
The full database has dozens of tables in several schemas (Sales, Production, Person and others). The LT edition keeps the core of the business, customers, products and orders, in about ten tables, which is easier for learning.
Which SQL dialect do I use?
T-SQL, the SQL Server dialect. For example, use TOP or OFFSET … FETCH instead of LIMIT.