A complete SQL Server Data Warehouse built using a layered Medallion Architecture for data integration, transformation, data quality validation, and analytics.
This project implements a SQL Server Data Warehouse using a layered Bronze, Silver, and Gold architecture.
The warehouse integrates data from CRM and ERP CSV sources, loads the source data into the Bronze layer, cleans and standardizes it in the Silver layer, and creates business-ready views in the Gold layer.
The final Gold layer follows a Star Schema with customer and product dimensions connected to a sales fact.
The warehouse follows a Medallion Architecture where each layer has a specific responsibility.
CRM CSV Files ───────┐
│
▼
┌───────────────┐
│ BRONZE LAYER │
│ Raw Data │
└───────┬───────┘
│
▼
┌───────────────┐
│ SILVER LAYER │
│ Cleaned Data │
└───────┬───────┘
│
▼
┌───────────────┐
│ GOLD LAYER │
│ Star Schema │
└───────────────┘
▲
│
ERP CSV Files ────────┘
| Layer | Purpose | Main Work |
|---|---|---|
| Bronze | Store source data | CSV ingestion and raw storage |
| Silver | Clean and standardize data | Transformation, validation and deduplication |
| Gold | Prepare analytical data | Dimensions, fact view and business-ready integration |
The warehouse receives data from two source systems.
CRM provides:
- Customer information
- Product information
- Sales transaction information
Files:
cust_info.csv
prd_info.csv
sales_details.csv
ERP provides:
- Customer information
- Location information
- Product category information
Files:
CUST_AZ12.csv
LOC_A101.csv
PX_CAT_G1V2.csv
The Bronze layer stores the source data in its original form.
bronze.crm_cust_info
bronze.crm_prd_info
bronze.crm_sales_details
bronze.erp_cust_az12
bronze.erp_loc_a101
bronze.erp_px_cat_g1v2
The Bronze loading process is handled by:
bronze.load_bronze
The procedure:
- Truncates existing Bronze tables.
- Loads CRM CSV files.
- Loads ERP CSV files.
- Uses
BULK INSERT. - Displays loading progress.
- Tracks individual table load duration.
- Tracks total batch duration.
- Uses
TRY...CATCHfor error handling.
scripts/
└── bronze_layer/
├── DDL_bronze.sql
└── product_load_bronze.sql
The Silver layer transforms raw Bronze data into cleaned and standardized data.
The Silver loading process is handled by:
silver.load_silver
CRM customer data is cleaned by:
- Removing duplicate customer records.
- Keeping the latest customer record.
- Using
ROW_NUMBER()for deduplication. - Removing unwanted spaces.
- Standardizing marital status.
- Standardizing gender values.
S → Single
M → Married
Other → n/a
F → Female
M → Male
Other → n/a
CRM product data is transformed by:
- Separating category and product keys.
- Standardizing product line values.
- Handling missing product costs.
- Converting date values.
- Creating product validity periods using
LEAD().
M → Mountain
R → Road
S → Other Sales
T → Touring
Other → n/a
Sales data is transformed and validated by:
- Converting date values.
- Handling invalid dates.
- Validating order, shipping and due dates.
- Validating sales, quantity and price relationships.
- Handling invalid sales values.
- Handling invalid prices.
The main consistency rule is:
Sales = Quantity × Price
ERP customer data is cleaned by:
- Removing the
NASprefix from customer IDs. - Handling future birth dates.
- Standardizing gender values.
Example:
NAS000110001
↓
000110001
Location data is standardized by:
- Removing hyphens from customer IDs.
- Standardizing country names.
Examples:
DE → Germany
US → United States
USA → United States
UK → United Kingdom
ERP product category data is loaded into:
silver.erp_px_cat_g1v2
This data is later integrated with CRM product information in the Gold layer.
Silver quality checks are maintained separately in:
tests/quality_checks_silver.sql
The checks validate:
- NULL and duplicate keys.
- Unwanted spaces.
- Negative values.
- Data standardization.
- Product date ranges.
- Sales date relationships.
- Sales, quantity and price consistency.
- Customer birthdate ranges.
- Country values.
- Product category values.
The Gold layer contains the final analytical views.
The Gold layer combines cleaned Silver data and creates a Star Schema.
gold.dim_customers
gold.dim_products
gold.fact_sales
gold.dim_customers
The customer dimension combines:
silver.crm_cust_info
silver.erp_cust_az12
silver.erp_loc_a101
customer_key
customer_id
customer_number
first_name
last_name
country
marital_status
gender
birthdate
create_date
A surrogate key is generated using:
ROW_NUMBER()CRM gender information is used as the primary source, with ERP gender information used as a fallback when required.
gold.dim_products
The product dimension combines:
silver.crm_prd_info
silver.erp_px_cat_g1v2
product_key
product_id
product_number
product_name
category_id
category
subcategory
maintenance
cost
product_line
start_date
Only current product records are included:
WHERE pn.prd_end_dt IS NULLgold.fact_sales
The sales fact connects sales transactions with the customer and product dimensions.
order_number
product_key
customer_key
order_date
shipping_date
due_date
sales_amount
quantity
price
The fact view uses the surrogate keys from the Gold dimensions.
The final Gold layer follows a Star Schema.
┌─────────────────────┐
│ dim_customers │
│ │
│ customer_key │
│ customer_id │
│ customer_number │
│ first_name │
│ last_name │
│ country │
│ gender │
└──────────┬──────────┘
│
│
▼
┌─────────────────────┐
│ fact_sales │
│ │
│ order_number │
│ customer_key │
│ product_key │
│ order_date │
│ sales_amount │
│ quantity │
│ price │
└──────────┬──────────┘
│
│
▼
┌─────────────────────┐
│ dim_products │
│ │
│ product_key │
│ product_id │
│ product_number │
│ product_name │
│ category │
│ subcategory │
│ cost │
└─────────────────────┘
Gold quality checks are maintained separately in:
tests/quality_checks_gold.sql
The checks validate:
- Uniqueness of
customer_key.
- Uniqueness of
product_key.
- Fact-to-customer relationship.
- Fact-to-product relationship.
- Referential integrity between fact and dimensions.
The objective is to ensure that the Gold model is properly connected for analytical use.
The implemented data flow is:
CRM CSV Files
│
▼
┌─────────────────┐
│ Bronze Layer │
│ Raw Source │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Silver Layer │
│ Cleaned & │
│ Standardized │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Gold Layer │
│ Dimensions + │
│ Fact View │
└────────┬────────┘
│
▼
Analytical Data
ERP CSV Files
│
└──────────────► Bronze Layer
The project is executed in the following sequence:
1. Initialize SQL Server database and schemas
│
▼
2. Create Bronze tables
│
▼
3. Execute bronze.load_bronze
│
▼
4. Create Silver tables
│
▼
5. Execute silver.load_silver
│
▼
6. Run Silver quality checks
│
▼
7. Create Gold dimension and fact views
│
▼
8. Run Gold quality checks
| Area | Technology |
|---|---|
| Database | SQL Server |
| Query Language | T-SQL |
| Development Environment | SQL Server Management Studio |
| Data Loading | BULK INSERT |
| Data Processing | Stored Procedures |
| Architecture | Medallion Architecture |
| Data Modeling | Star Schema |
| Version Control | Git / GitHub |
The project uses practical SQL Server and T-SQL concepts.
CREATE DATABASE
CREATE SCHEMA
CREATE TABLE
CREATE VIEW
CREATE PROCEDURE
ALTER PROCEDURE
DROP TABLE
DROP VIEW
BULK INSERT
INSERT INTO
TRUNCATE TABLE
CASE
TRIM()
REPLACE()
SUBSTRING()
LEN()
CAST()
ISNULL()
COALESCE()
NULLIF()
GETDATE()
SELECT
WHERE
LEFT JOIN
GROUP BY
HAVING
ORDER BY
ROW_NUMBER()
LEAD()
TRY...CATCH
ERROR_MESSAGE()
ERROR_NUMBER()
ERROR_STATE()
Duplicate detection
NULL validation
Date validation
Value validation
Relationship validation
Standardization checks
sql-data-warehouse-project/
│
├── datasets/
│ ├── source_crm/
│ │ ├── cust_info.csv
│ │ ├── prd_info.csv
│ │ └── sales_details.csv
│ │
│ └── source_erp/
│ ├── CUST_AZ12.csv
│ ├── LOC_A101.csv
│ └── PX_CAT_G1V2.csv
│
├── docs/
│ ├── data-architecture.png
│ ├── data_catalog.md
│ ├── data_flow.png
│ ├── data_integration.png
│ ├── data_layers.pdf
│ ├── data_model.png
│ └── naming_conventions.md
│
├── scripts/
│ │
│ ├── bronze_layer/
│ │ ├── DDL_bronze.sql
│ │ └── product_load_bronze.sql
│ │
│ ├── silver_layer/
│ │ ├── DDL_silver.sql
│ │ └── proc_load_silver.sql
│ │
│ ├── gold_layer/
│ │ └── DDL_gold.sql
│ │
│ └── init_database.sql
│
├── tests/
│ ├── quality_checks_silver.sql
│ └── quality_checks_gold.sql
│
├── .gitignore
├── LICENSE
├── README.md
└── requirements.txt
The SQL scripts are separated according to the warehouse layer.
scripts/bronze_layer/DDL_bronze.sql
scripts/bronze_layer/product_load_bronze.sql
Used for:
- Bronze table creation.
- Raw CRM and ERP data loading.
scripts/silver_layer/DDL_silver.sql
scripts/silver_layer/proc_load_silver.sql
Used for:
- Silver table creation.
- Data cleaning.
- Data transformation.
- Data standardization.
- Silver loading.
scripts/gold_layer/DDL_gold.sql
Used for:
- Customer dimension.
- Product dimension.
- Sales fact view.
tests/quality_checks_silver.sql
tests/quality_checks_gold.sql
Used for validating the Silver and Gold layers.
Supporting project documentation is maintained in the docs directory.
data-architecture.png
data_catalog.md
data_flow.png
data_integration.png
data_layers.pdf
data_model.png
naming_conventions.md
These documents describe the implemented warehouse architecture, data flow, data integration, data model, data layers, data catalog and naming conventions.
| Area | Implemented Work |
|---|---|
| Data Sources | CRM and ERP CSV data |
| Database | SQL Server |
| Language | T-SQL |
| Architecture | Bronze, Silver and Gold |
| Bronze Loading | Stored procedure + BULK INSERT |
| Silver Processing | Cleaning, transformation and standardization |
| Deduplication | ROW_NUMBER() |
| Date Processing | Validation and conversion |
| Data Validation | Silver and Gold quality checks |
| Gold Modeling | Customer and product dimensions + sales fact |
| Surrogate Keys | ROW_NUMBER() |
| Data Integration | CRM + ERP |
| Data Model | Star Schema |
The following components have been implemented:
- Database initialization
- Bronze table creation
- Bronze data loading
- Bronze stored procedure
- Silver table creation
- Silver data cleaning
- Silver data transformation
- Silver standardization
- Silver loading procedure
- Silver quality checks
- Gold customer dimension
- Gold product dimension
- Gold sales fact
- Gold quality checks
- CRM and ERP integration
- Star Schema modeling
- Supporting project documentation
The main focus of this project is building a clean, layered SQL Server Data Warehouse that transforms raw CRM and ERP data into reliable, standardized and business-ready data for analytical use.
Raw Source Data
↓
Data Ingestion
↓
Data Cleaning
↓
Data Transformation
↓
Data Quality Validation
↓
Dimensional Modeling
↓
Business-Ready Data