The “Known quality” check in our AI readiness scorecard asks whether you measure error rates in your key fields. Most small teams don’t, so problems surface as a strange dashboard number or a confused customer email. Six simple checks catch most of them early. Each is one short SQL query you can schedule.
To show what each check finds, we ran every query on a small orders table with problems planted on purpose: a missing amount, a duplicated order, a negative amount, a misspelled status, an order for a customer who doesn’t exist, and a feed that stopped three days ago. The queries use standard SQL (tested on SQLite); date functions differ slightly between databases.
1. Completeness: are required fields filled?
-- 1. Completeness: share of missing values in fields that must be filled
SELECT 'completeness' AS check_name,
ROUND(100.0 * SUM(amount IS NULL) / COUNT(*), 1) AS pct_missing_amount,
ROUND(100.0 * SUM(customer_id IS NULL) / COUNT(*), 1) AS pct_missing_customer
FROM orders;
Result: pct_missing_amount = 11.1. One order in nine has no amount. Decide a tolerance for each field: often zero for IDs and amounts, and higher for optional fields like a phone number.
2. Uniqueness: does each ID appear once?
-- 2. Uniqueness: IDs that should appear once but don't
SELECT 'uniqueness' AS check_name, order_id, COUNT(*) AS copies
FROM orders GROUP BY order_id HAVING COUNT(*) > 1;
Result: order 105 appears twice. Duplicates usually come from re-running an import or retrying a failed API call, and they inflate every sum built on the table.
3. Validity: are values in their allowed set and range?
-- 3. Validity: values outside the allowed set or range
SELECT 'validity' AS check_name, order_id, amount, status
FROM orders
WHERE amount < 0 OR status NOT IN ('pending', 'paid', 'shipped', 'refunded');
Result: order 104 has an amount of -30.0, and order 107 has the status shipped?. Note what this check missed: the order with a missing amount, because NULL < 0 is not true in SQL. That’s why completeness is a separate check.
4. Referential integrity: do references point at real records?
-- 4. Referential integrity: orders pointing at customers that don't exist
SELECT 'integrity' AS check_name, o.order_id, o.customer_id
FROM orders o LEFT JOIN customers c ON c.customer_id = o.customer_id
WHERE c.customer_id IS NULL;
Result: order 105 belongs to customer 9, who isn’t in the customers table. Joins silently drop such rows, so revenue by customer, country or segment comes out lower than total revenue, and nobody can say why.
5. Freshness: is the data still arriving?
-- 5. Freshness: how old is the newest record? (compare with how often data should arrive)
SELECT 'freshness' AS check_name, MAX(created_at) AS newest,
CAST(julianday('2026-11-29') - julianday(MAX(created_at)) AS INTEGER) AS days_old
FROM orders;
Result: the newest order is 3 days old. If orders normally arrive daily, an import has stopped. This is the most valuable check to alert on, because a stale table looks perfectly healthy otherwise.
6. Volume: is today’s amount of data normal?
-- 6. Volume: rows per day, to compare the latest day with the recent average
SELECT 'volume' AS check_name, created_at AS day, COUNT(*) AS orders
FROM orders GROUP BY created_at ORDER BY created_at DESC LIMIT 7;
Result: one or two orders a day in the sample. In production, compare the latest day with the average of the previous seven and alert when it falls outside a band you choose, for example below half or above double. A sudden drop often means a broken feed; a spike often means duplicates.
Download all six checks as one file: data-quality-checks.sql, ready to adapt to your tables, with PostgreSQL and MySQL notes and a volume check that compares the latest day with the previous seven.
Putting the checks to work
- Start with one table: the one behind your most important KPI (see How to Build a KPI Tree).
- Run the checks on a schedule, before dashboards refresh or models read the data. A cron job, a database scheduler or your BI tool’s alerts all work.
- Alert on failures only, with the query result in the message, so the person on duty sees what broke.
- Turn every incident into a check. When a bad number reaches a meeting, add the query that would have caught it.
What each check catches
| Check | Typical cause it catches |
|---|---|
| Completeness | Form fields made optional, failed enrichment, API changes |
| Uniqueness | Re-run imports, retried API calls |
| Validity | Typos, new status values nobody told you about, sign errors |
| Referential integrity | Deleted parents, out-of-order loads |
| Freshness | Stopped feeds, expired credentials |
| Volume | Partial loads, duplicates, tracking removed from a page |
Six queries won’t make data perfect, but they turn “the numbers look off” into a specific, fixable failure, and that’s the foundation every dashboard and AI project needs.
Prepared with AI assistance and reviewed by an editor before publication. Editorial & AI policy.