• nuevo

    Lanzamiento 2026.06 - Llevando la Data Observability a su código

  • nuevo

    Contribuya al futuro de la innovación en IA y datos

  • nuevo

    • Lanzamiento 2026.06 - Llevando la Data Observability a su código

  • nuevo

    • Contribuya al futuro de la innovación en IA y datos

Database Integrity Testing: A Practical Guide for 2026

|

0

minuto de lectura

You can have a pipeline that's technically green and still produce a finance dashboard nobody trusts. The jobs finish, the tests pass, and the rows are there, but the ledger doesn't reconcile with the revenue number on the screen. That gap is where database integrity testing earns its keep, because it checks whether the data is still correct after storage, joins, migrations, transforms, and time.

Table of Contents

When Green Tests Still Ship Broken Data

The alert came from finance, not engineering. A dashboard showed a revenue figure that did not match the ledger, but every pipeline check had passed, and the warehouse looked healthy on paper. An analytics engineer traced the flow back through staging, transformations, and reporting layers, then found the uncomfortable truth, the database had no obvious integrity violation, yet the business answer was still wrong.

That is the trap with ordinary checks. Row counts can look fine, a DAG can turn green, and a basic freshness test can pass while a foreign-key relationship is broken, a duplicate key was introduced during a backfill, or a transformation changed historical totals. In practice, integrity depends on the validation strategy wrapped around the database, not on the presence of the database itself, and mutation testing has shown how wide that gap can be, with weakest coverage criteria killing only 12% of mutants while the strongest killed up to 96% in a 2015 analysis (McMinn 2015).

A cleaner way to frame the problem is the distinction between data quality and data integrity, which the team at digna treats as related but not identical concerns.

Why this deserves its own discipline

Database integrity testing sits beside general data quality work. It checks whether records remain accurate, consistent, valid, and uncorrupted as they move through storage and change, and it needs negative tests that try to violate rules instead of only confirming the happy path. That matters because a system can still be populated, queryable, and wrong.

Industry guidance now frames integrity around five core dimensions, accuracy, completeness, consistency, timeliness, and validity (Matillion). The same point appears in IBM's guidance on data integrity testing, which emphasizes checking whether the database enforces the rules you expect across storage and retrieval. That model is useful because it moves teams away from a single pass or fail mindset and toward layered controls that match the way modern warehouses, lakes, and pipelines fail.

What Database Integrity Testing Really Means

A diagram illustrating database integrity testing concepts, including data accuracy, consistency, structural rules, and independent app testing.

A database can look healthy on the surface and still carry bad records. Database integrity testing checks whether data stays correct and uncorrupted while it is stored, retrieved, replicated, and transformed, and whether the database is enforcing the rules the system depends on. It sits at the boundary between schema enforcement and runtime behavior, so the test surface needs to cover both.

A simple customers-and-orders system makes the point quickly. Each order should point to a real customer, each customer identifier should stay unique, and fields such as order status or quantity should remain inside the allowed set. If one of those promises breaks, the database may still accept the row unless the rule has been encoded and tested.

The classical integrity types

Entity integrity means each row has a unique identifier and that identifier is not null. A primary key has to do its job, or records start to blur together and downstream joins become unreliable.

Referential integrity means child rows point to real parent rows. If an order references a customer that does not exist, the system creates an orphan, and reporting can start to miscount or misclassify records.

Domain integrity keeps values inside the allowed range, type, or list. That might be a CHECK constraint, a data type, or a rule that blocks invalid status codes before they spread.

Semantic integrity is the business layer that schema alone cannot express. An updated_at value should not be earlier than created_at, and an order should not be marked paid if the payment table shows no transaction.

Practical rule: if a schema constraint can express the rule, test the constraint directly. If business logic owns the rule, test the behavior that proves it.

That split between structural checks and broader quality controls is where data quality vs data integrity becomes useful, because it clarifies which failures belong to the database itself and which belong to the surrounding pipeline or application logic.

The Five Dimensions Every Integrity Test Should Cover

A diagram illustrating the five core dimensions of data integrity: accuracy, completeness, consistency, timeliness, and validity.

A table can pass its basic constraints and still produce bad decisions. The row exists, the type is correct, and the join works, yet the number may be stale, incomplete, or contradicted by another system. That is why integrity testing needs to cover more than primary keys and foreign keys. It has to check the specific ways data can look valid while still being untrustworthy.

The five-dimension model helps teams avoid overfitting to one failure mode. Each critical table should be mapped to the dimension most likely to break there, because the right test for a customer key is not the right test for a revenue snapshot. Classical constraints catch structural violations, while continuous checks catch changes in behavior, freshness, and cross-system agreement. For schema changes that alter those rules, see schema drift and why structural changes break pipelines.

What each dimension catches

Accuracy asks whether the value is right. A revenue total can still be wrong even when the row is present and the type checks out, so the test needs to compare the output against the expected calculation or source of truth.

Completeness asks whether the expected records or fields are present. A missing month of transactions is a different failure from a bad value, and it usually calls for count checks, presence checks, or partition-level checks. If an ingestion job drops a slice of data, completeness is the first place that gap should show up.

Consistency looks for contradictions across systems or layers. A customer marked active in one table and closed in another is a sign that the model has drifted, and the mismatch may only show up when two tables are compared side by side.

Timeliness checks freshness. A load that lands at 11:55 PM but is treated as current at 9 AM should fail a timeliness rule, even if every row is valid. Freshness matters because delayed data can be accurate and still mislead anyone reading it as current.

Validity asks whether the data fits the allowed format or rule set. Malformed email strings, impossible status values, and bad dates belong here, along with any field that violates the business rules attached to its type.

A good testing habit is to write for the failure mode, not for SQL convenience. If a table stores dates, counts, customer identifiers, and business states, one query might confirm part of the picture, but it rarely proves all five dimensions at once. The cleaner approach is to decide what can fail, then choose the check that would expose that failure most directly.

Operational insight: a green test suite that only checks completeness can still miss a wrong revenue calculation, a stale batch, or a record that is valid on its own but inconsistent with the rest of the model.

That is why the five dimensions have become a baseline for enterprise governance in regulated settings, especially where auditability and freshness matter as much as correctness.

Designing Integrity Test Cases That Break Things

The best integrity tests do not celebrate the happy path, they try to make the model fail. If a rule is real, the test should be able to violate it on purpose and prove the database rejects the bad input or exposes the broken behavior. That is how you find cases where a migration dropped a constraint or an ETL refactor stopped enforcing logic.

Negative cases that expose weak controls

A duplicate primary key should fail immediately if entity integrity is real. An orphan child row should fail if referential integrity is enforced. An invalid enum value, a child inserted before its parent, or a negative quantity in a table that should never accept one all tell you whether the rule exists in the database or only in documentation.

The same approach works for semantic checks. A paid order with zero payment transactions should fail a validation query. So should a row where updated_at is earlier than created_at. These are the kinds of tests that catch silent problems after a release, especially when the database still “looks fine.”

Common integrity test cases and what they catch

Test case

Integrity type

What it catches

Example assertion

Duplicate primary key insert

Entity

Missing uniqueness enforcement

Fails if duplicate key is accepted

Orphan child row

Referential

Broken parent-child relationship

Fails if child has no parent

Invalid enum or status

Domain

Weak value constraints

Fails if disallowed value is stored

Child-before-parent insert

Referential

Missing sequencing control

Fails if FK rule is bypassed

Paid order with no payment row

Semantic

Broken business process

Fails if payment state is inconsistent

Negative quantity

Domain

Impossible business values

Fails if negative value is stored

updated_at earlier than created_at

Semantic

Bad lifecycle logic

Fails if timestamps violate ordering

For a schema-level view of how these failures often start, the internal note on schema drift explained is a useful companion. Structural drift can weaken constraints, and the symptom may not appear until a downstream check finally compares expected behavior with what the database is doing.

Assertion language should be blunt. “Duplicate customer ID was accepted,” “orphan order line found,” and “payment state does not match transaction records” are better than vague pass-fail messages because they tell the next engineer exactly what broke.

A useful pattern is to pair these point-in-time failures with the same rules watched inside the database over time. The static test proves the constraint exists. Ongoing observability shows whether real data keeps crossing the edge cases that matter, such as repeated orphan creation after a deployment or a status field drifting away from the allowed set. That combination gives you both the guardrail and the warning light.

If you want a platform to express these checks inside the database instead of shipping data out for validation, digna is one option among others. Its rule-based validation and in-database execution model fit this style of testing, where the point is to catch broken relationships where the data already lives.

Embedding Integrity Tests in CI/CD and Migrations

A schema change that ships without rerunning integrity checks creates a blind spot, and that is usually where broken data gets through. A dependable release process keeps migrations and integrity assertions together, so the rules that protect keys, relationships, and allowed values travel with the code that changes them.

What the release flow should look like

Start with version control. A developer changes the schema, transformation logic, or business rule, and the CI pipeline runs unit tests plus integrity tests against a cloned database. The migration should be applied in two places, a fresh database and a populated one, because a change that works on empty tables can still fail once real rows, foreign keys, and edge cases are present.

After deployment, run the same assertions again. That second pass matters because a migration may apply cleanly while still changing constraint behavior, query plans, or validation outcomes. Teams also need to decide up front whether the migration is reversible or formally accepted as irreversible, instead of leaving that question open after release (bug0).

Where the tools fit

Frameworks like pgTAP for PostgreSQL and tSQLt for SQL Server let teams express integrity checks as code, which makes the checks reviewable and repeatable. Query-level validation belongs in the same workflow, especially for critical paths, and EXPLAIN ANALYZE can surface performance regressions before a change reaches downstream reporting or analytics. The same discipline also shows up in Enterprise data validation inside the database, where the checks stay close to the tables they protect.

Production snapshots are another strong pattern. They let you verify that a change behaves the same way on live-shaped data without touching the live system itself. That matters when a table is large, business-critical, or regulated, because empty-test behavior can hide problems that only appear at scale or with historical records.

In the same way that anomaly detection for dealers watches for unusual shifts in behavior over time, in-database integrity testing watches for rules that still pass on paper but fail against real data movement. Static assertions catch the broken constraint. Release-time and post-release checks show whether the migration keeps the database honest once the new code is in place.

From Point-in-Time Tests to Continuous Integrity Observability

A test suite can pass and the dashboard can still be wrong. That usually happens when the problem isn't a broken constraint, it's drift over time, delayed delivery, a schema change, or a transformation that changed history without tripping a hard failure. Continuous integrity observability fills the gap left by one-off validation.

Why static tests aren't enough

Traditional integrity tests are good at catching explicit violations, like orphan rows or invalid values. They're weaker when the pipeline changes slowly, because yesterday's correct output can become today's wrong answer without any single failure event. Reprocessing, backfills, and refactors are common sources of that kind of quiet breakage, and public guidance increasingly treats that as a separate operational problem rather than a pure database problem (Soda).

That's why teams are adding anomaly detection, schema change tracking, and delivery-pattern monitoring on top of deterministic checks. These signals help you see the shape of the data, not just whether it breaks a rule. If a table usually arrives at a certain time and starts arriving later, or if a metric shifts in a way that doesn't match prior behavior, you want the alert before a business user opens the dashboard.

How observability extends integrity

An effective setup watches for three things together. First, record-level validation proves the hard rules still hold. Second, timeliness monitoring flags late or missing loads based on expected delivery patterns. Third, schema tracking catches structural changes before downstream jobs fail on a surprise column rename or type change.

A useful companion reference is anomaly detection for dealers, because it shows how baseline-aware detection can surface unusual behavior without forcing every team to hand-write a rule for every edge case.

Practical rule: if a check only tells you that bad data arrived, add an observability signal that tells you when the system started drifting toward bad data.

Continuous observability doesn't replace integrity tests. It catches the failures tests can't schedule for, especially in pipelines that reprocess history or depend on upstream systems you don't control.

Measuring Coverage, SLAs, and Real ROI

More tests don't automatically mean more protection. A long list of checks can look impressive and still miss the tables that matter most. The better question is whether the test suite covers the data that can hurt the business if it breaks.

Coverage should follow risk

Critical tables deserve deeper coverage than reference data, and change-sensitive pipelines deserve more attention than stable ones. Downstream models, regulatory datasets, and KPI tables sit near the top of the list because missed rows, late loads, or broken joins can distort reporting and compliance evidence. Many public guides discuss documentation and audits, but they rarely define what “good coverage” means in a mixed warehouse, lake, and pipeline environment (VirtuosoQA).

Set SLAs that match the data's role. If a dataset drives morning reporting, the team needs a freshness expectation that's tighter than a batch archive. If a schema changes frequently, the control that matters is not how many checks exist, it's whether the change was caught before users felt the impact.

A risk-reduction mindset

Integrity testing is a risk-reduction program, not a vanity test count.

That framing makes it easier to justify investment in regulated environments, where the cost of a missed row, a late load, or a corrupted KPI can show up as audit friction, bad decisions, or rework across analytics and operations. The ROI comes from preventing those failures, not from chasing exhaustive validation on every table.

A practical way to start is to rank datasets by business consequence, then assign monitoring depth accordingly. That gives you a better balance than trying to test everything equally.

Putting It All Together Into a Trustworthy Data Stack

A diagram illustrating the four layers of a trustworthy data stack, from schema constraints to continuous monitoring.

A trustworthy stack has layers, and each layer solves a different kind of failure. Schema constraints are the floor, they stop obvious violations at the database boundary. Integrity tests are the backbone, they prove the rules still work after code changes, loads, and migrations. CI/CD is the release gate, it blocks changes that would break those rules. Continuous monitoring is the overlay, it watches for drift, delay, and structural change after deployment.

A simple operating model

At the warehouse or lake boundary, constraints keep invalid records out. Inside the pipeline, test cases check entity, referential, domain, and semantic integrity before data reaches consumers. In release management, migrations and assertions move together so the team can prove a change didn't alter behavior. After release, observability watches the live system for late arrivals, schema drift, and statistical anomalies.

That layered approach also fits governance. Running checks in-database keeps data in place, which helps with security and reduces unnecessary movement. Combining deterministic validation with behavioral monitoring is what lets teams catch both hard violations and quiet drift.

A senior data team can summarize the model in one sentence. Database integrity testing is not a single tool, it's a layered program that pairs classical database discipline with modern observability so downstream consumers can trust the data.

If you want help building that layered model inside your own environment, digna provides in-database validation, schema tracking, timeliness monitoring, and anomaly detection across warehouses, lakes, and pipelines. Visit digna to see how those controls can fit into your data stack and support the integrity checks your team needs.

Compartir en X
Compartir en X
Compartir en Facebook
Compartir en Facebook
Compartir en LinkedIn
Compartir en LinkedIn

Conoce al equipo detrás de la plataforma

Un equipo con sede en Viena de expertos en IA, datos y software respaldado

por el rigor académico y la experiencia empresarial.

Conoce al equipo detrás de la plataforma

Un equipo con sede en Viena de expertos en IA, datos y software respaldado
por el rigor académico y la experiencia empresarial.

Producto

Integraciones

Recursos

Empresa