An end-to-end modern data warehouse and ETL pipeline built with Microsoft SQL Server following the Medallion Architecture (Bronze β Silver β Gold). This project transforms raw, unorganized extracts from disparate ERP and CRM source systems into validated, modeled, business-ready dimensions and facts structured in a Star Schema optimized for Business Intelligence (BI) and reporting.
- π Project Overview
- ποΈ High-Level Architecture
- π Source Systems & Data Integration
- π Data Flow & Lineage
- β Data Mart & Dimensional Modeling
- π Project Structure
- π Execution Order & Pipeline Setup
- π§ͺ Data Quality & Validation
- π Data Dictionary
- π οΈ Tech Stack
- π€ Author & Acknowledgments
Organizations often struggle with data silos where transactional sales and customer information are split across enterprise systems (e.g., CRM and ERP) with duplicate entities, formatting inconsistencies, and invalid records.
This project solves those challenges by implementing an enterprise-grade data warehouse pipeline featuring:
- Idempotent Ingestion: Raw CSV extraction into the Bronze Layer using efficient
BULK INSERTbatch loading. - Data Cleansing & Standardization: Silver-layer transformation procedures handling nulls, trimming unwanted whitespace, standardizing gender/marital status, deduplicating customer profiles, and correcting inconsistent sales calculations.
- Dimensional Modeling: Gold-layer Star Schema with surrogate keys (
customer_key,product_key) and facts (fact_sales) enabling high-performance slicing and dicing. - Quality Assurance & Testing: Pre- and post-load SQL test suites ensuring 100% data integrity, referential consistency, and schema contract compliance.
The warehouse follows the industry-standard Medallion Architecture:
- Bronze Layer (Raw): Landing zone storing raw source data as-is from CRM and ERP CSV exports with fast full load / truncation.
- Silver Layer (Cleaned & Conformed): Cleansed, deduplicated, enriched, and standardized data with historical timeline normalization.
- Gold Layer (Business Ready): Analytics-ready Star Schema (Dimensions & Facts) modeled via SQL Views, consumed directly by BI dashboards (Power BI / Tableau) and ad-hoc SQL reporting.
The data warehouse consolidates two main operational systems:
- CRM System:
crm_cust_info: Customer profiles (Name, Gender, Marital Status, Create Date).crm_prd_info: Product master data (Cost, Line, Start/End Dates).crm_sales_details: Transactional orders (Order Number, Quantity, Price, Sales Amount).
- ERP System:
erp_cust_az12: Customer birthdates and gender info.erp_loc_a101: Customer geographical data (Country codes).erp_px_cat_g1v2: Product categories, subcategories, and maintenance flags.
The end-to-end data lineage from raw CSV files through Bronze, Silver, and into Gold presentation views:
The Gold layer presents a business-friendly Star Schema with 1 Fact table and 2 Dimension tables:
gold.dim_customers: Master customer dimension blending CRM demographics with ERP geographical locations and birthdates, featuring a surrogate primary key (customer_key).gold.dim_products: Cleaned product dimension filtered for active products (prd_end_dt IS NULL) with standardized category and subcategory hierarchies.gold.fact_sales: Central fact table storing sales transactions, linking to dimensions through surrogate foreign keys (customer_key,product_key).
sql-data-warehouse-project/
βββ datasets/ # Raw CSV Source Datasets
β βββ source_crm/ # CRM source files (cust_info, prd_info, sales_details)
β βββ source_erp/ # ERP source files (CUST_AZ12, LOC_A101, PX_CAT_G1V2)
βββ docs/ # Architecture diagrams and documentation
β βββ architecture.drawio.png # High-Level Architecture Diagram
β βββ data_flow.png # End-to-end data lineage diagram
β βββ data_integration_model.drawio.png # Source-to-target entity relationship model
β βββ data_model.png # Gold Layer Star Schema diagram
β βββ data_catalog.md # Comprehensive Data Dictionary for Gold Layer
βββ scripts/ # SQL Scripts (DDL & ETL Procedures)
β βββ init_database.sql # Database & schema creation (DataWarehouse, schemas)
β βββ bronze/ # Bronze Layer scripts
β β βββ ddl_bronze.sql # DDL script for raw Bronze tables
β β βββ proc_load_bronze.sql # Stored procedure to bulk insert raw CSVs
β β βββ exec_load_bronze.sql # Execution script for Bronze load
β βββ silver/ # Silver Layer scripts
β β βββ ddl_silver.sql # DDL script for conformed Silver tables
β β βββ proc_load_silver.sql # Stored procedure transforming Bronze -> Silver
β βββ gold/ # Gold Layer scripts
β βββ ddl_gold.sql # DDL script creating Star Schema analytical views
βββ tests/ # Automated Quality Check Suites
β βββ quality_checks_bronze.sql # Quality profiling queries on raw Bronze data
β βββ quality_checks_silver.sql # Validation tests on cleansed Silver layer
β βββ quality_checks_gold.sql # Referential & key integrity checks on Gold views
βββ LICENSE # MIT License
βββ README.md # Project documentation
Follow these steps in SQL Server Management Studio (SSMS) to deploy and run the entire warehouse from scratch:
Execute scripts/init_database.sql to drop (if exists), recreate the DataWarehouse database, and initialize the bronze, silver, and gold schemas.
- Run
scripts/bronze/ddl_bronze.sqlto create all raw tables. - Run
scripts/bronze/proc_load_bronze.sqlto compile thebronze.load_bronzestored procedure. - Run
scripts/bronze/exec_load_bronze.sql(orEXEC bronze.load_bronze;) to load all CSV datasets into Bronze.
- Run
scripts/silver/ddl_silver.sqlto create conformed Silver tables. - Run
scripts/silver/proc_load_silver.sqlto compile thesilver.load_silvertransformation procedure. - Execute
EXEC silver.load_silver;to clean, normalize, deduplicate, and populate all Silver tables.
Run scripts/gold/ddl_gold.sql to generate the Star Schema views (dim_customers, dim_products, fact_sales).
Execute the test suites in tests/:
tests/quality_checks_silver.sql: Verifies zero duplicates, no unwanted spaces, valid date ranges, and calculation accuracy.tests/quality_checks_gold.sql: Validates foreign key referential integrity and surrogate key uniqueness.
Data quality is enforced at every layer through dedicated testing scripts:
| Test Category | Description | Target Layer |
|---|---|---|
| Primary Key Uniqueness | Ensures surrogate keys (customer_key, product_key) contain no duplicates or NULLs |
Silver / Gold |
| Referential Integrity | Verifies all fact records link to existing dimension records without orphans | Gold |
| String Hygiene | Detects and removes leading/trailing whitespace (cst_key, names) |
Silver |
| Domain & Standardization | Standardizes gender (Male/Female), marital status (Married/Single), and country codes |
Silver |
| Calculation Integrity | Validates sales formulas: Sales Amount = Quantity * Price (handles missing/negative values) |
Silver |
| Chronological Validity | Verifies order_date <= shipping_date and start_date <= end_date |
Silver / Gold |
A full field-by-field metadata catalog covering data types, business descriptions, and surrogate keys for the Gold Layer is available in docs/data_catalog.md.
- Database Engine: Microsoft SQL Server
- Language: Transact-SQL (T-SQL)
- Tooling: SQL Server Management Studio (SSMS), Git, draw.io
- Concepts: Medallion Architecture, ETL / ELT, Dimensional Modeling (Star Schema), Surrogate Keys, Data Cleansing, Data Integrity Testing
- Author: @bishal7448
- Project Structure: Inspired by modern data engineering best practices and Baraa Khatib Salkini's (Data With Baraa) data warehouse architecture.
This project is open-source and available under the MIT License.



