ETL Testing Using SQL: Tips and Query Examples

 ✅ ETL Testing Using SQL: Tips and Query Examples

ETL Testing (Extract, Transform, Load Testing) is the process of validating data as it moves from source systems to the data warehouse. SQL is a vital tool in ETL testing because it helps you validate data accuracy, completeness, and integrity at every step of the ETL process.


🧩 What is ETL Testing?

ETL Testing ensures:


Data is correctly extracted from source systems.


Data is properly transformed as per business rules.


Data is accurately loaded into the target system or warehouse.


πŸ” Key ETL Testing Activities Using SQL

Test Type Goal SQL Example

Row Count Validation Check source vs target row counts SELECT COUNT(*) FROM table_name;

Data Comparison Check if values match between systems SELECT * FROM source MINUS SELECT * FROM target;

Null Checks Ensure mandatory fields are not NULL SELECT * FROM table WHERE column IS NULL;

Data Type Validation Confirm correct data types in columns SELECT COLUMN_NAME, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'TABLE';

Duplicate Check Detect duplicate rows SELECT column, COUNT(*) FROM table GROUP BY column HAVING COUNT(*) > 1;

Transformation Rules Verify logic like concatenation or math `SELECT first_name

Referential Integrity Validate foreign key constraints SELECT * FROM child WHERE parent_id NOT IN (SELECT id FROM parent);


πŸ§ͺ Common SQL Queries for ETL Testing

1. Row Count Match

sql

Copy

Edit

-- Source

SELECT COUNT(*) FROM source_table;


-- Target

SELECT COUNT(*) FROM target_table;

2. Data Validation Between Source and Target

sql

Copy

Edit

-- Find mismatched rows

SELECT * FROM source_table

MINUS

SELECT * FROM target_table;

3. Duplicate Records

sql

Copy

Edit

SELECT id, COUNT(*)

FROM target_table

GROUP BY id

HAVING COUNT(*) > 1;

4. Null Value Check

sql

Copy

Edit

SELECT * FROM target_table

WHERE important_column IS NULL;

5. Check Transformed Columns

For example, a salary increase by 10%:


sql

Copy

Edit

SELECT employee_id, salary, new_salary

FROM transformed_table

WHERE new_salary != salary * 1.10;

πŸ’‘ ETL Testing Best Practices

✅ Understand business rules before writing SQL.


🧾 Validate metadata: column names, types, lengths, and formats.


πŸ“Š Use control tables to compare expected vs actual data loads.


πŸ•΅️‍♂️ Log errors and mismatches for debugging.


πŸ”„ Test incremental loads with timestamp or ID-based queries.


πŸ’Ύ Back up data before re-running ETL jobs during testing.


⏱️ Monitor performance of long-running SQL queries.


🧠 Summary

SQL is the backbone of effective ETL testing. By writing smart, targeted queries, you can:


Detect data issues early.


Verify transformations.


Ensure the reliability of your data pipeline.

Learn ETL Testing Training in Hyderabad

Read More

Common ETL Bugs and How to Find Them

How to Perform Data Validation in ETL Testing

Step-by-Step Guide to Writing ETL Test Cases

Why ETL Testing is Crucial in Data Warehousing

Visit Our IHUB Talent Training Institute in Hyderabad

Get Directions 

Comments

Popular posts from this blog

How to Install and Set Up Selenium in Python (Step-by-Step)

Feeling Stuck in Manual Testing? Here’s Why You Should Learn Automation Testing

A Beginner's Guide to ETL Testing: What You Need to Know