data2al icon data2al Data Engineering Notes and Code Patterns

Concept note

Check For Null And Duplicate Keys

A fast validation query for checking whether a model has null keys or duplicate identifiers.

2025-04-17
Alan
SQL
Beginner
SQL Data Quality Validation

This is a useful warehouse check before exposing a model to downstream dashboards, marts, or APIs.

Example

select
    count(*) as total_rows,
    count_if(order_id is null) as null_order_ids,
    count(*) - count(distinct order_id) as duplicate_order_ids
from analytics.fct_orders;

Why this pattern helps

  • gives a quick signal on model integrity
  • catches two common data contract failures in one query
  • is easy to embed into testing or monitoring workflows

Notes

  • rename the key column to match the model you are validating
  • schedule this check after transformations complete
  • alert on non-zero results when the table is consumed by production reporting

Similar Posts