A modern data warehouse built in SQL (MySQL) using the Medallion Architecture — Bronze, Silver, and Gold layers. The project ingests raw CSV data from two source systems (CRM and ERP), cleans and standardizes it through an ETL pipeline, and exposes a business-ready star schema for BI, reporting, and analytics.
The warehouse follows the three-layer medallion pattern. Data flows left to right — from raw source files, through progressive refinement, to analytics consumers.
| Layer | Object Type | Load Strategy | Transformations | Data Model |
|---|---|---|---|---|
| Bronze | Tables | Batch · Full load · Truncate & Insert | None — raw, as-is | None |
| Silver | Tables | Batch · Full load · Delete & Insert | Cleaning, standardization, normalization, derived columns, enrichment | None |
| Gold | Views | No load (views on Silver) | Data integration, aggregation, business logic | Star schema |
- Sources: CRM and ERP, delivered as CSV files in folders.
- Consumers: BI & reporting tools (e.g. Power BI), SQL ad-hoc analysis, and AI/ML workloads.
SQL_DataWarehouse_Project/
│
├── datasets/ # Raw source data (CSV)
│ ├── source_crm/
│ │ ├── cust_info.csv # Customer master (~18.5k rows)
│ │ ├── prd_info.csv # Product master (~397 rows)
│ │ └── sales_details.csv # Sales transactions (~60k rows)
│ └── source_erp/
│ ├── CUST_AZ12.csv # ERP customer demographics (birthdate, gender)
│ ├── LOC_A101.csv # ERP customer location / country
│ └── PX_CAT_G1V2.csv # Product category / subcategory lookup
│
├── scripts/
│ ├── sql_database_setup # Creates the database + bronze/silver/gold schemas
│ ├── bronzelayer/
│ │ ├── bronzelayer_ddl.sql # DDL: bronze tables
│ │ └── bronzelayer_dataloading.sql # BULK load CSVs into bronze
│ ├── silverlayer/
│ │ ├── silverlayer_ddl.sql # DDL: silver tables (+ dwh_create_date)
│ │ └── silverlayer_dataloading.sql # Stored proc: ETL bronze → silver
│ └── goldlayer/
│ └── goldlayer_creatingviews.sql # Gold views: dim_customer, dim_product, fact_sales
│
├── tests/
│ ├── silverlayer_datachecking_cleaning.sql # Quality checks for the silver layer
│ └── goldlayer_querytesting.sql # Integrity & relationship checks for gold
│
├── docs/ # Architecture & data-model diagrams (.drawio + .png)
│ ├── Project Datawarehouse Architecture.png
│ ├── data_flow_diagram.png
│ ├── data_integration.png
│ └── data_model_goldlayer.png
│
├── LICENSE # MIT
└── README.md
Loads the six source CSVs as-is into bronze tables. Each table is truncated and reloaded via MySQL LOAD DATA LOCAL INFILE (bulk insert), with per-table and total load timings. No transformation is applied — the bronze layer is a faithful copy of the source.
A stored procedure, silver.load_silver(), runs the ETL from bronze to silver inside a transaction (with an error handler that rolls back on failure). Key transformations include:
- Customers (
crm_cust_info): deduplicate by latestcst_create_date, trim names, decode marital status (M/S→ Married/Single) and gender (M/F→ Male/Female). - Products (
crm_prd_info): splitprd_keyinto acat_key(joins to ERP category) and product key, mapprd_linecodes to labels (Road, Mountain, Touring, Other Sales), and deriveprd_end_dtfrom the next product's start date (LEAD). - Sales (
crm_sales_details): convert integerYYYYMMDDdates to properDATE, and recompute invalid/missingsalesandprice(sales = quantity × ABS(price)). - ERP demographics (
erp_cust_az12): stripNASprefix from IDs, null out future birthdates, normalize gender. - ERP location (
erp_loc_a101): normalize country codes (US/USA→ United States,DE→ Germany).
Every silver table carries a dwh_create_date metadata column.
Three views model the data for consumption:
gold.dim_customer— one row per customer, enriched from CRM + ERP, with a surrogatecustomer_key. Gender falls back from CRM to ERP when missing.gold.dim_product— current products only (prd_end_dt IS NULL), with a surrogateproduct_keyand category/subcategory from ERP.gold.fact_sales— sales transactions joined to the two dimensions via their surrogate keys.
- MySQL 8.0+ (the scripts use window functions, CTEs, stored procedures, and
LOAD DATA LOCAL INFILE). - MySQL Workbench or any MySQL client.
-
Create the database and schemas
-- scripts/sql_database_setup⚠️ This drops and recreates the databases — all existing data is permanently deleted. Run with caution. -
Enable local file loading (required for the bulk load)
- Server side:
SET GLOBAL local_infile = 1; - Client side (Workbench): connection → Advanced tab → Others box → add
OPT_LOCAL_INFILE=1, then reconnect.
- Server side:
-
Build & load Bronze
source scripts/bronzelayer/bronzelayer_ddl.sql; source scripts/bronzelayer/bronzelayer_dataloading.sql;
📌 Update the
LOAD DATA LOCAL INFILE '...'file paths inbronzelayer_dataloading.sqlto point to this repo'sdatasets/folder on your machine (they currently use absolute paths from the author's environment). -
Build Silver & run the ETL
source scripts/silverlayer/silverlayer_ddl.sql; source scripts/silverlayer/silverlayer_dataloading.sql; -- creates the procedure CALL silver.load_silver(); -- runs the ETL
-
Create the Gold views
source scripts/goldlayer/goldlayer_creatingviews.sql;
-
(Optional) Run quality checks
source tests/silverlayer_datachecking_cleaning.sql; source tests/goldlayer_querytesting.sql;
Once complete, query the gold views directly — for example:
SELECT * FROM gold.fact_sales;
SELECT * FROM gold.dim_customer;
SELECT * FROM gold.dim_product;The tests/ scripts validate the warehouse after loading:
- Silver: null/duplicate primary keys, unwanted whitespace, value standardization, consistency across related fields, and invalid date ranges.
- Gold: uniqueness of surrogate keys, referential integrity between facts and dimensions, and validation of the data-model relationships.
- snake_case for all objects; English only; no SQL reserved words.
- Bronze / Silver:
<sourcesystem>_<entity>(e.g.crm_cust_info,erp_loc_a101) — names match the source. - Gold:
<category>_<entity>with a business-aligned name (e.g.dim_customer,fact_sales). - Surrogate keys:
<entity>_key(e.g.customer_key). - Technical columns:
dwh_<name>(e.g.dwh_create_date). - Load procedures:
load_<layer>(e.g.load_silver).
See docs/Define Project Naming Conventions ...md for the full specification.
- Database: MySQL
- Language: SQL (DDL, DML, stored procedures, window functions)
- Architecture: Medallion (Bronze / Silver / Gold)
- Modeling: Star schema (fact + dimension views)
- Diagrams: draw.io
Released under the MIT License. See LICENSE.
Author: Darshil Parikh

