In this post we are going to cover the most basic question in the series: what is a data warehouse? It sounds easy, but a good answer needs more than "a big database for reports".
A data warehouse is a central database that stores integrated, historical data from many source systems, organized for analysis and reporting. The classic definition comes from Bill Inmon, who is often called the father of data warehousing. He described it with four words: subject-oriented, integrated, time-variant and non-volatile.
If you can explain those four words with an example, you have answered the question better than most candidates. So we will go through each one, and show three of them with SQL on TB Shop data.
Question 3 of the Real DWH Question and Answers series on TechBrothersIT.
The interview answer
A data warehouse is a central database that stores integrated, historical data from many source systems, organized for analysis and reporting. Bill Inmon defined it as subject-oriented, integrated, time-variant and non-volatile.
Where the warehouse sits
Let's first see where a data warehouse sits in a company.
- Sources in - for TB Shop that is the website database, the in-store point of sale system, the CRM and a few spreadsheets with targets and budgets.
- ETL or ELT - pipelines copy data out of each source, clean it, match it and load it.
- The warehouse - inside, the data is organized by business subject: sales, customers, products and inventory.
- Analysis out - dashboards, analysts and data scientists all read the same trusted numbers.
Subject-oriented
Source systems are organized around applications. The website database, the store system and the CRM each have their own tables, built for their own screens: web_orders, pos_sales, contacts and so on.
A warehouse is organized around business subjects instead: sales, customers, products, inventory. Customers from the website and from the stores end up in one customer subject. So when someone asks a business question, they go to the subject, not to the application that happened to capture the data.
Let's create some sample data
We create two customer sources, an empty warehouse dim_customer table that we will load, a table of month-end stock snapshots, and an order status history table that we will only ever append to.
DROP TABLE IF EXISTS web_customers;
DROP TABLE IF EXISTS store_customers;
DROP TABLE IF EXISTS dim_customer;
DROP TABLE IF EXISTS inventory_snapshot;
DROP TABLE IF EXISTS order_status_history;
-- Source 1: the website database
CREATE TABLE web_customers (
cust_id VARCHAR(10) PRIMARY KEY,
name VARCHAR(50),
gender CHAR(1), -- 'F' / 'M'
country CHAR(2) -- 'CA' / 'US'
);
INSERT INTO web_customers VALUES
('W1', 'Sara Khan', 'F', 'CA'),
('W2', 'Omar Ali', 'M', 'US');
-- Source 2: the in-store point-of-sale system
CREATE TABLE store_customers (
customer_no INT PRIMARY KEY,
full_name VARCHAR(50),
sex VARCHAR(10), -- 'Female' / 'Male'
country_name VARCHAR(50) -- 'Canada' / 'USA'
);
INSERT INTO store_customers VALUES
(501, 'Lina Park', 'Female', 'USA'),
(502, 'Mei Chen', 'Female', 'Canada');
-- Warehouse: one customer table, one standard format
CREATE TABLE dim_customer (
source VARCHAR(10),
source_id VARCHAR(10),
name VARCHAR(50),
gender VARCHAR(10),
country VARCHAR(50)
);
-- Warehouse: month-end stock snapshots (time-variant)
CREATE TABLE inventory_snapshot (
snapshot_date DATE,
product VARCHAR(50),
units_in_stock INT
);
INSERT INTO inventory_snapshot VALUES
('2026-01-31', 'Desk Lamp', 40), ('2026-01-31', 'Wireless Mouse', 60),
('2026-02-28', 'Desk Lamp', 25), ('2026-02-28', 'Wireless Mouse', 55),
('2026-03-31', 'Desk Lamp', 12), ('2026-03-31', 'Wireless Mouse', 70);
-- Warehouse: order status history (non-volatile: we only ever append)
CREATE TABLE order_status_history (
order_id INT,
status VARCHAR(20),
status_date DATE
);
INSERT INTO order_status_history VALUES (1005, 'Placed', '2026-03-03');Here are the customers from the website.
SELECT * FROM web_customers ORDER BY 1;| cust_id | name | gender | country |
|---|---|---|---|
| W1 | Sara Khan | F | CA |
| W2 | Omar Ali | M | US |
The website stores gender as F or M, and country as CA or US.
And here are the customers from the store system.
SELECT * FROM store_customers ORDER BY 1;| customer_no | full_name | sex | country_name |
|---|---|---|---|
| 501 | Lina Park | Female | USA |
| 502 | Mei Chen | Female | Canada |
The store system writes Female, Male, Canada and USA, and even uses different column names. Same kind of data, two formats.
Step 1: Integrated - two sources, one format
If we just copied both tables in, every report would have to deal with two spellings of the same thing, and totals by country would come out split. So let's convert everything to one standard while loading. This SQL maps the website codes to full words, and stacks both sources into one customer table with a source column.
INSERT INTO dim_customer
SELECT 'WEB', cust_id, name,
CASE gender WHEN 'F' THEN 'Female' ELSE 'Male' END,
CASE country WHEN 'CA' THEN 'Canada' ELSE 'USA' END
FROM web_customers
UNION ALL
SELECT 'STORE', CAST(customer_no AS VARCHAR(10)),
full_name, sex, country_name
FROM store_customers;Now let's check the result.
SELECT * FROM dim_customer ORDER BY name;| source | source_id | name | gender | country |
|---|---|---|---|---|
| STORE | 501 | Lina Park | Female | USA |
| STORE | 502 | Mei Chen | Female | Canada |
| WEB | W2 | Omar Ali | Male | USA |
| WEB | W1 | Sara Khan | Female | Canada |
Four customers from two systems, now in one consistent format: every gender is Female or Male and every country is Canada or USA. Sara Khan came in as F and CA and is now Female and Canada. That is what integrated means: same names, same codes, same meaning, wherever the data came from.
Step 2: Time-variant - stock over time
The shop database knows the stock level right now. Ask it what the stock was at the end of January, and it has no idea. The warehouse stores a snapshot of stock at the end of every month, and each row carries its date. Let's look at the Desk Lamp.
SELECT snapshot_date, units_in_stock
FROM inventory_snapshot
WHERE product = 'Desk Lamp'
ORDER BY snapshot_date;| snapshot_date | units_in_stock |
|---|---|
| 2026-01-31 | 40 |
| 2026-02-28 | 25 |
| 2026-03-31 | 12 |
Desk Lamp went from 40 units at the end of January, to 25 in February, to 12 in March. That is a trend you can only see because every row carries a date, and it tells the business it is time to reorder. Time-variant simply means every piece of data is tied to a point in time, and the warehouse keeps years of it.
Step 3: Non-volatile - append, don't overwrite
In the shop database, order 1005 has one status column.
| order_id | status |
|---|---|
| 1005 | Placed |
When the order ships, the app overwrites Placed with Shipped. When it arrives, it overwrites again, and the old values are gone. In the warehouse we don't update in place. Every change arrives as a new row. Let's append the two status changes for order 1005.
INSERT INTO order_status_history VALUES
(1005, 'Shipped', '2026-03-05'),
(1005, 'Delivered', '2026-03-08');Now let's check the result.
SELECT * FROM order_status_history ORDER BY status_date;| order_id | status | status_date |
|---|---|---|
| 1005 | Placed | 2026-03-03 |
| 1005 | Shipped | 2026-03-05 |
| 1005 | Delivered | 2026-03-08 |
The warehouse now holds all three statuses with their dates: Placed on 2026-03-03, Shipped on 2026-03-05 and Delivered on 2026-03-08. Nothing was updated or deleted. Because the history is kept, we can now measure that this order took two days to ship and five days from order to delivery.
Non-volatile means that once data is in the warehouse, it stays as it was. New data is added, old data is not changed.
Follow-up questions interviewers ask
Database vs data warehouse?
A data warehouse is a database designed for analytics: integrated from many sources, historical and read-heavy.
What is a data mart?
A smaller, subject-specific part of the warehouse built for one team, such as finance or marketing.
Data lake vs data warehouse?
A lake stores raw files of any format cheaply; a warehouse stores cleaned, structured, modeled data for SQL analytics.
The full script
Here is everything from this post in one script. Copy it and run it top to bottom.
-- ========================================================================
-- Data Warehouse Interview Q&A #3 - What is a data warehouse?
-- TechBrothersIT. Sample data is invented for teaching.
-- Standard SQL, tested on PostgreSQL 16. Runs top to bottom in one go.
-- Run it in an empty database or schema: other videos reuse table names
-- like dim_customer, and their leftover tables can block the DROPs below.
-- PostgreSQL example: CREATE SCHEMA dwh_q03; SET search_path TO dwh_q03;
-- ========================================================================
-- Step 0: create and load the sample data
DROP TABLE IF EXISTS web_customers;
DROP TABLE IF EXISTS store_customers;
DROP TABLE IF EXISTS dim_customer;
DROP TABLE IF EXISTS inventory_snapshot;
DROP TABLE IF EXISTS order_status_history;
-- Source 1: the website database
CREATE TABLE web_customers (
cust_id VARCHAR(10) PRIMARY KEY,
name VARCHAR(50),
gender CHAR(1), -- 'F' / 'M'
country CHAR(2) -- 'CA' / 'US'
);
INSERT INTO web_customers VALUES
('W1', 'Sara Khan', 'F', 'CA'),
('W2', 'Omar Ali', 'M', 'US');
-- Source 2: the in-store point-of-sale system
CREATE TABLE store_customers (
customer_no INT PRIMARY KEY,
full_name VARCHAR(50),
sex VARCHAR(10), -- 'Female' / 'Male'
country_name VARCHAR(50) -- 'Canada' / 'USA'
);
INSERT INTO store_customers VALUES
(501, 'Lina Park', 'Female', 'USA'),
(502, 'Mei Chen', 'Female', 'Canada');
-- Warehouse: one customer table, one standard format
CREATE TABLE dim_customer (
source VARCHAR(10),
source_id VARCHAR(10),
name VARCHAR(50),
gender VARCHAR(10),
country VARCHAR(50)
);
-- Warehouse: month-end stock snapshots (time-variant)
CREATE TABLE inventory_snapshot (
snapshot_date DATE,
product VARCHAR(50),
units_in_stock INT
);
INSERT INTO inventory_snapshot VALUES
('2026-01-31', 'Desk Lamp', 40), ('2026-01-31', 'Wireless Mouse', 60),
('2026-02-28', 'Desk Lamp', 25), ('2026-02-28', 'Wireless Mouse', 55),
('2026-03-31', 'Desk Lamp', 12), ('2026-03-31', 'Wireless Mouse', 70);
-- Warehouse: order status history (non-volatile: we only ever append)
CREATE TABLE order_status_history (
order_id INT,
status VARCHAR(20),
status_date DATE
);
INSERT INTO order_status_history VALUES (1005, 'Placed', '2026-03-03');
-- Step 1: Integrate two sources into one standard customer table
INSERT INTO dim_customer
SELECT 'WEB', cust_id, name,
CASE gender WHEN 'F' THEN 'Female' ELSE 'Male' END,
CASE country WHEN 'CA' THEN 'Canada' ELSE 'USA' END
FROM web_customers
UNION ALL
SELECT 'STORE', CAST(customer_no AS VARCHAR(10)),
full_name, sex, country_name
FROM store_customers;
-- check the result
SELECT * FROM dim_customer ORDER BY name;
-- Step 2: Time-variant: how did Desk Lamp stock change over time?
SELECT snapshot_date, units_in_stock
FROM inventory_snapshot
WHERE product = 'Desk Lamp'
ORDER BY snapshot_date;
-- Step 3: Non-volatile: append new status rows instead of updating
INSERT INTO order_status_history VALUES
(1005, 'Shipped', '2026-03-05'),
(1005, 'Delivered', '2026-03-08');
-- check the result
SELECT * FROM order_status_history ORDER BY status_date;
Key points
- A central store of integrated, historical data, built for analysis
- Subject-oriented: organized by sales, customers, products
- Integrated: many sources, one standard format
- Time-variant: every row is tied to a point in time
- Non-volatile: new data is appended, old data is not changed
Question 4 — ETL vs ELT What is the difference between ETL and ELT?
Every query and every result on this page was run on PostgreSQL 16 using the script above. The SQL is standard and runs on most databases with small changes (noted in the script). All tables and data are invented demo data for teaching.



No comments:
Post a Comment
Note: Only a member of this blog may post a comment.