Skip to content

About

Building a modern data warehouse using SQL Server, covering ETL processes, data modeling, and data analytics. Includes SQL scripts demonstrating advanced analytical techniques such as time-based trends, cumulative analysis, performance analysis, data segmentation, and part-to-whole analysis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏒 Modern Data Warehouse & ETL Project (SQL Server)

SQL Server T-SQL Architecture Model License: MIT

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.


πŸ“‘ Table of Contents


πŸ“Œ Project Overview

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 INSERT batch 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.

πŸ—οΈ High-Level Architecture

The warehouse follows the industry-standard Medallion Architecture:

High-Level Architecture

  1. Bronze Layer (Raw): Landing zone storing raw source data as-is from CRM and ERP CSV exports with fast full load / truncation.
  2. Silver Layer (Cleaned & Conformed): Cleansed, deduplicated, enriched, and standardized data with historical timeline normalization.
  3. 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.

πŸ”„ Source Systems & Data Integration

The data warehouse consolidates two main operational systems:

Data Integration Model

  • 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.

🌊 Data Flow & Lineage

The end-to-end data lineage from raw CSV files through Bronze, Silver, and into Gold presentation views:

Data Flow and Lineage


⭐ Data Mart & Dimensional Modeling

The Gold layer presents a business-friendly Star Schema with 1 Fact table and 2 Dimension tables:

Data Mart Star Schema

  • 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).

πŸ“‚ Project Structure

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

πŸš€ Execution Order & Pipeline Setup

Follow these steps in SQL Server Management Studio (SSMS) to deploy and run the entire warehouse from scratch:

1️⃣ Initialize Database & Schemas

Execute scripts/init_database.sql to drop (if exists), recreate the DataWarehouse database, and initialize the bronze, silver, and gold schemas.

2️⃣ Build & Load Bronze Layer (Raw Ingestion)

  1. Run scripts/bronze/ddl_bronze.sql to create all raw tables.
  2. Run scripts/bronze/proc_load_bronze.sql to compile the bronze.load_bronze stored procedure.
  3. Run scripts/bronze/exec_load_bronze.sql (or EXEC bronze.load_bronze;) to load all CSV datasets into Bronze.

3️⃣ Build & Load Silver Layer (Cleansing & Transformation)

  1. Run scripts/silver/ddl_silver.sql to create conformed Silver tables.
  2. Run scripts/silver/proc_load_silver.sql to compile the silver.load_silver transformation procedure.
  3. Execute EXEC silver.load_silver; to clean, normalize, deduplicate, and populate all Silver tables.

4️⃣ Build Gold Layer (Dimensional Views)

Run scripts/gold/ddl_gold.sql to generate the Star Schema views (dim_customers, dim_products, fact_sales).

5️⃣ Run Quality Assurance Tests

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 & Validation

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

πŸ“– Data Dictionary

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.


πŸ› οΈ Tech Stack

  • 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 & Acknowledgments

  • Author: @bishal7448
  • Project Structure: Inspired by modern data engineering best practices and Baraa Khatib Salkini's (Data With Baraa) data warehouse architecture.

πŸ“„ License

This project is open-source and available under the MIT License.

About

Building a modern data warehouse using SQL Server, covering ETL processes, data modeling, and data analytics. Includes SQL scripts demonstrating advanced analytical techniques such as time-based trends, cumulative analysis, performance analysis, data segmentation, and part-to-whole analysis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages