SQL Server database for a B2B distributor's order-to-delivery process. The project covers customer orders, shipments, returns, stock movements and a small reporting layer built with T-SQL.
All records are synthetic. The database can be rebuilt from scratch and produces the same dataset on every run.
| Area | Included |
|---|---|
| Operational model | Customers, products, orders, order lines, shipments and returns |
| Inventory | Warehouses, stock movements and current balances |
| Reporting | Reusable views and parameterised stored procedures |
| Data quality | Ten checks with persisted run history |
| Test data | Deterministic T-SQL generation for 400 customers and 5,000 orders |
| Validation | Fail-fast deployment and smoke tests |
The database is split into four schemas:
sales— customers, orders, shipments and returnsinventory— products, warehouses, movements and balancesreporting— analytical views and reporting proceduresaudit— data quality runs and results
The operational model is normalised. Order values are derived from order lines, while inventory movements provide the audit trail behind each current balance.
See the ERD and data dictionary for the full model.
Requirements:
- SQL Server 2019 or later
sqlcmdor SQL Server Management Studio with SQLCMD Mode
From the repository root:
sqlcmd `
-S localhost `
-E `
-C `
-b `
-i ".\run_all.sql" `
-v DatabaseName="B2BOrderAnalytics"The script drops and recreates B2BOrderAnalytics. A successful run ends with:
All smoke tests passed.
Build completed successfully.
Run the analysis scripts after the build:
sqlcmd `
-S localhost `
-d B2BOrderAnalytics `
-E `
-C `
-b `
-i ".\sql\06_analysis\60_business_questions.sql" `
-W `
-s "|"More commands are available in the execution guide.
reporting.vw_OrderLineDetailsreporting.vw_OrderSummaryreporting.vw_MonthlySalesreporting.vw_CustomerMetricsreporting.vw_ProductPerformancereporting.vw_InventoryStatusreporting.vw_FulfillmentPerformance
reporting.usp_GetSalesPerformancereporting.usp_GetCustomerOrderHistoryinventory.usp_AdjustStockaudit.usp_RunDataQualityChecks
The main query pack answers ten questions:
- How is monthly revenue changing?
- Which products lead revenue and gross margin?
- Which customers account for the most value?
- How does delivery performance vary by warehouse?
- Which categories have the highest return rates?
- Which products require replenishment?
- How concentrated is revenue among the top customers?
- How do sales channels compare?
- How many customers place repeat orders?
- Did the latest data quality run pass?
The companion dataset profile checks customer participation, order frequency, channel mix and product-demand concentration.
A deterministic build produced:
- 400 customers, with 320 placing at least one order
- 237 repeat customers and 83 one-time customers
- 74.06% repeat-customer rate
- 43.96% of sold units concentrated in the 15 most popular products
- 10 data quality checks passed, with no failures
Enterprise accounts represented 32.96% of completed orders but 58.89% of net revenue. Online sales had the highest gross-margin rate, while partner orders had a higher average value but a lower margin rate.
See results.md for the supporting figures.
.
├── docs/
│ ├── business_rules.md
│ ├── data_dictionary.md
│ ├── data_generation.md
│ ├── erd.md
│ ├── execution_guide.md
│ └── results.md
├── outputs/
├── sql/
│ ├── 00_setup/
│ ├── 01_ddl/
│ ├── 02_seed/
│ ├── 03_views/
│ ├── 04_procedures/
│ ├── 05_quality/
│ ├── 06_analysis/
│ └── 07_tests/
├── run_all.sql
└── README.md
- One shipment per order
- One currency and no tax calculation
- No partial fulfillment or backorder workflow
- Current stock is maintained alongside the movement ledger
- Data is generated for analysis and testing, not copied from a live system
MIT Licence.
The powerbi/ directory contains a Power BI Project connected to the dimensional reporting layer in the mart schema.
The report is organised into three pages:
Executive Overview- revenue, customer mix, channel economics, fulfillment and inventory alertsFulfillment & Returns- delivery reliability, warehouse performance, carriers and return driversInventory & Products- stock health, product demand and replenishment priorities
Open the project after rebuilding the database:
powerbi/B2BOrderAnalytics.pbip
The report connects to localhost and the B2BOrderAnalytics database using Windows authentication.