Customers sample database for SQL Server
A ready-to-run SQL Server script with a customer list with segments, order counts, lifetime spend and activity. Tested on SQL Server 2022 16.0.4325.4. Updated 19 November 2026.
Customers database for SQL Server
Each row is one fictional customer account: contact details on reserved example domains and 555-01xx numbers, city, signup date, segment, orders so far, lifetime spend and whether they ordered in 2024.
This page has it as a SQL Server script: one table and 1,000 rows, with column types chosen for SQL Server, primary keys. The script drops the table if it exists, creates it and inserts the rows in one transaction, so you can run it again to reset the data. It is the same fictional data, seed 42, as on the customers dataset page, where it is also available as CSV and Excel.
We loaded this exact file into SQL Server 2022 16.0.4325.4 and ran every question below on it; the answers shown are that output. The same questions, written for SQLite, PostgreSQL, MySQL, SQL Server and DuckDB, return the same results on all five.
Load it
sqlcmd
sqlcmd -S localhost -Q "CREATE DATABASE practice"
sqlcmd -S localhost -d practice -i customers-sqlserver.sqlSSMS or Azure Data Studio
Create a database, open the .sql file in a new query window connected to it, and press Execute.
Tables and columns
customers 1,000 rows
| Column | SQL Server type |
|---|---|
| customer_id | NVARCHAR(10) |
| first_name | NVARCHAR(20) |
| last_name | NVARCHAR(20) |
| NVARCHAR(40) | |
| phone | NVARCHAR(20) |
| city | NVARCHAR(20) |
| state | NVARCHAR(10) |
| signup_date | DATE |
| segment | NVARCHAR(20) |
| total_orders | INT |
| total_spent | DECIMAL(10,2) |
| last_order_date | DATE |
| is_active | BIT |
Practice questions
answers from SQL Server 2022 16.0.4325.4
How many customers are in each segment, and what share is active?
SQL
SELECT segment, COUNT(*) AS customers,
ROUND(CAST(100 * SUM(CASE WHEN is_active = 1 THEN 1 ELSE 0 END) AS DECIMAL(18,6)) / NULLIF(COUNT(*), 0), 2) AS active_pct
FROM customers
GROUP BY segment
ORDER BY customers DESC, segment;Yes/no columns are BIT: 1 is true and 0 is false.
Result
| segment | customers | active_pct |
|---|---|---|
| Consumer | 718 | 45.40 |
| Small Business | 211 | 49.76 |
| Enterprise | 71 | 53.52 |
Which 5 customers have spent the most?
SQL
SELECT TOP 5 customer_id, first_name, last_name, total_spent
FROM customers
ORDER BY total_spent DESC, customer_id;SELECT TOP n ... ORDER BY returns the first n rows; SQL Server has no LIMIT.
Result
| customer_id | first_name | last_name | total_spent |
|---|---|---|---|
| CU10591 | Wei | Thompson | 24,199.09 |
| CU10976 | Charles | Martinez | 22,975.28 |
| CU10217 | Charles | Torres | 22,133.56 |
| CU10046 | Diego | Jackson | 19,470.90 |
| CU10872 | Donna | Moore | 19,309.66 |
How many customers signed up each year?
SQL
SELECT YEAR(signup_date) AS signup_year, COUNT(*) AS customers
FROM customers
GROUP BY YEAR(signup_date)
ORDER BY signup_year;YEAR(date) returns the year as a number.
Result
| signup_year | customers |
|---|---|
| 2019 | 176 |
| 2020 | 152 |
| 2021 | 153 |
| 2022 | 166 |
| 2023 | 176 |
| 2024 | 177 |
Which 5 states have the most customers?
SQL
SELECT TOP 5 state, COUNT(*) AS customers, ROUND(SUM(total_spent), 2) AS spent
FROM customers
GROUP BY state
ORDER BY customers DESC, state;SELECT TOP n ... ORDER BY returns the first n rows; SQL Server has no LIMIT.
Result
| state | customers | spent |
|---|---|---|
| CA | 151 | 251,780.94 |
| TX | 123 | 177,933.87 |
| NY | 102 | 192,295.73 |
| IL | 62 | 106,761.43 |
| FL | 59 | 78,504.24 |
How many customers have no last order date (never ordered)?
SQL
SELECT COUNT(*) AS no_order_date
FROM customers
WHERE last_order_date IS NULL;Result
| no_order_date |
|---|
| 53 |
What is the average order value (total spent ÷ total orders) per segment?
SQL
SELECT segment, ROUND(CAST(SUM(total_spent) AS DECIMAL(18,6)) / NULLIF(SUM(total_orders), 0), 2) AS avg_order_value
FROM customers
GROUP BY segment
ORDER BY segment;Integer divided by integer truncates in SQL Server, so the numerator is cast to DECIMAL first.
Result
| segment | avg_order_value |
|---|---|
| Consumer | 73.82 |
| Enterprise | 611.63 |
| Small Business | 208.85 |
SQL Server differences used here
- Yes/no columns are BIT: 1 is true and 0 is false.
- Integer divided by integer truncates in SQL Server, so the numerator is cast to DECIMAL first.
- SELECT TOP n ... ORDER BY returns the first n rows; SQL Server has no LIMIT.
- YEAR(date) returns the year as a number.