DEV Community

Prachit Parikh
Prachit Parikh

Posted on Edited on

7 SQL checks I run before UAT sign-off (with queries you can copy)

The hour I trust least on any project is the one right before UAT sign-off. The testers have clicked through every screen, the defect board is mostly green, and someone is waiting for a signature. Screens can look perfect while the data underneath is wrong, though, and nobody finds out until the first month-end report goes to finance.

So before I sign anything as the business analyst, I run a short set of SQL checks against the test environment. It takes about an hour. The checks are built for the problems that weeks of manual testing tend to walk right past: a load that silently drops a slice of rows, a currency field that doubles on one branch of the data, customers who have orders but no customer record.

Here are the seven checks, with generic queries you can adapt. The table names are made up, so swap in your own.

Prefer to watch? In my video Dashboard Numbers Don't Match? Find the Gap in SQL, I reconcile two revenue numbers in SQL step by step: the definition, the calendar, the grain of the joins, and orphan rows.

Related: If an AI assistant drafted the query, run it through my 8-check review for AI-generated SQL before you trust the number.

Why a business analyst should write SQL at all

You don't need to be a data engineer. You need to be able to answer one question without waiting on anyone: "Is the data in the new system what the business expects?" Developers test that the code does what the spec says. A BA's job is to check that the spec, and the data it produces, matches what the business needs. SQL is the fastest way to do that yourself.

If you can write SELECT, GROUP BY, JOIN and CASE, you can run every check below.

1. Row counts: did everything arrive?

Start with the dumbest possible question. If the source had 48,210 orders for a day, does the target have 48,210?

SELECT 'source' AS side, COUNT(*) AS row_count
FROM staging.orders
WHERE load_date = '2026-10-30'
UNION ALL
SELECT 'target', COUNT(*)
FROM dw.fact_orders
WHERE load_date = '2026-10-30';
🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน 🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน

If the numbers differ, ask why before anything else. Sometimes there's a good reason (test orders filtered out on purpose). Often there isn't.

2. Totals that should tie out

Counts can match while amounts don't. Sum the money by a period the business cares about and compare.

SELECT DATE_TRUNC('month', order_date) AS month,
       SUM(order_amount) AS total_amount
FROM dw.fact_orders
GROUP BY 1
ORDER BY 1;
🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน 🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน

Run the same query on the source or the legacy report. Put the two side by side in Excel with a difference column. Any month that doesn't tie to the cent gets a defect.

3. Duplicates on the business key

Duplicates are the classic silent killer. One order counted twice inflates revenue and nobody notices until an auditor does.

SELECT order_number, COUNT(*) AS copies
FROM dw.fact_orders
GROUP BY order_number
HAVING COUNT(*) > 1
ORDER BY copies DESC;
🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน 🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน

Use the key the business uses, not the surrogate ID the database made up. An order number, invoice number or account number is what people will actually reconcile against.

4. Orphans: records pointing at nothing

Every order should belong to a customer that exists. Every transaction should belong to an account that exists.

SELECT o.order_number, o.customer_id
FROM dw.fact_orders o
LEFT JOIN dw.dim_customer c
       ON c.customer_id = o.customer_id
WHERE c.customer_id IS NULL;
🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน 🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน

Orphans usually mean the loads ran in the wrong order or a lookup failed. Reports built on an inner join will quietly drop these rows, which is how totals go missing.

5. Nulls in fields the business depends on

Go back to the requirements. Which fields did stakeholders say were mandatory? Check them.

SELECT COUNT(*) AS total_rows,
       SUM(CASE WHEN region IS NULL THEN 1 ELSE 0 END) AS missing_region,
       SUM(CASE WHEN product_code IS NULL THEN 1 ELSE 0 END) AS missing_product,
       SUM(CASE WHEN order_amount IS NULL THEN 1 ELSE 0 END) AS missing_amount
FROM dw.fact_orders;
🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน 🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน

A dashboard filtered by region will hide every row with a null region. That's a requirement failure even if no screen ever throws an error.

6. Values outside the allowed list

If the requirement says status can only be Open, Shipped, Cancelled or Returned, prove it.

SELECT status, COUNT(*) AS rows_with_status
FROM dw.fact_orders
WHERE status NOT IN ('Open', 'Shipped', 'Cancelled', 'Returned')
   OR status IS NULL
GROUP BY status;
🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน 🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน

This one finds mapping gaps fast. A legacy code like "SHP" that nobody mapped will show up here instead of in a confused user's email three weeks after go-live.

7. Trace five real records end to end

Not every check is a query. Pick five records the business knows well: a big customer, a refund, an order that changed status twice, something from the last day of a month. Follow each one from the source screen, through the tables, to the final report. Write down what you see at every step.

Queries tell you the data is consistent. Tracing real records tells you it means what people think it means.

How I log the results

I keep one simple table per test cycle:

Check Query saved as Expected Actual Pass/Fail Defect
Row count 30 Oct rc_orders.sql 48,210 48,210 Pass
Duplicates dup_orders.sql 0 14 Fail DEF-212

Each row links back to a requirement in the traceability matrix, so when someone asks "did we test that?", the answer is one click away. It also makes the sign-off conversation short: here's what we checked, here's what passed, here are the open defects and their severity.

When a check fails

Don't sign off with a known data defect and a promise to fix it later. Raise it with the exact query attached, the expected result, and the actual result. Developers can rerun it in seconds, and nobody has to argue about what "the numbers look off" means.

Then agree on severity with the business owner, not alone. A 14-row duplicate in a test table might be minor. A 14-row duplicate in a revenue report is not.

The one-page version

Before you sign UAT, confirm:

  • Row counts match between source and target for at least two load dates
  • Money totals tie out by month
  • No duplicates on the business key
  • No orphan records on any key relationship
  • Mandatory fields have no nulls
  • Coded fields only contain allowed values
  • Five real records traced end to end
  • Every failure has a defect with the query attached

That's an hour of work that protects weeks of everyone else's.

About me

I'm Prachit Parikh, a business analyst. I turn what stakeholders ask for into requirements a team can test, check the data with SQL, and see changes through UAT. I keep free templates, including these SQL checks, in my BA Toolkit on GitHub, and I make short animated explainers on YouTube. Besides Dev.to, I write on Substack, Medium, Hashnode, Blogger and WordPress, and I answer questions on Quora. You can also find me on LinkedIn, Bluesky, Kaggle, Credly, Crunchbase and Gravatar. Everything is collected on my website and my profile hub.

What check would you add to this list? I'd like to hear the one that saved you on a project.

Top comments (34)

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
ontomato profile image
ontomato •

solid checklist. i still would not sign off on a total that never said what one row means.

order versus order line sounds pedantic until a join quietly multiplies the sum. nulls and duplicates can all pass while the grain is wrong. naming that grain before uat, then sitting a few rows at that level next to the aggregate, caught more bad sign offs for us than another null scan did.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
prachitparikh profile image
Prachit Parikh •

Agree, and I'd put the grain above all seven. One line at the top of the test plan, "one row = one order line," settles half the arguments before they start. Putting a few rows next to the total is a good habit too. I made a short video on exactly this, one join quietly inflating a sum: youtube.com/watch?v=SG-6rtZeizg

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
ontomato profile image
ontomato •

putting the grain first is exactly what i wish more plans opened with.

one line like 'one row = one order line' at the top probably settles more fights than another null scan. what worked for a teammate was forcing that sentence into the PR description before anyone looked at the seven checks. then sitting a few rows at that grain next to the total made the quiet join blowups obvious. i'll check your video on the inflated sum, that failure mode is the one i keep underestimating.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

Putting it in the PR description is a smart forcing function, because it's the one place nobody skips. I'm stealing that. The same line works as a UAT entry criterion: no grain sentence, no testing starts. Hope the video is useful, and tell me if the fan-out example looks like the blowups you've seen.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
ontomato profile image
ontomato •

Making the grain sentence a hard entry gate is sharper than leaving it as advice.

We tried the soft version first and people still skipped it under deadline. Once testing could not start without that one line in the PR, the fan-out cases showed up earlier, usually as an order-line total that quietly matched invoice count. Your video's blowup shape is the same one we keep walking into.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

That one's nasty because it looks like a pass. refaeldakar posted a cheap alarm for exactly this on emadaed's fan-out post: next to the total, print count(*) and count(DISTINCT order_id) for the same rows. If they differ, the grain is order line no matter what the PR says. Two numbers, and nobody has to argue about it.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
ontomato profile image
ontomato •

Printing both counts next to the total is a neat alarm.

If they differ, the grain is order line no matter what the PR title says. Two numbers end the argument faster than another meeting.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

That's what I like about it: nobody has to win the argument about grain, the two numbers settle it. I'd put both in the sign-off record too, so the next person who touches the query can see what the grain was on the day it passed.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
ontomato profile image
ontomato •

Yeah, putting both counts in the sign-off record makes it much easier for the next person to check.

I’d still probably want to keep the query version alongside them though. Then someone can rerun it and see whether a new join changed the grain, rather than trying to work backwards from a note that just says “order line.”

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

Agreed, a note on its own goes stale. I'd store the query file's commit hash next to the two counts in the sign-off record. The next person reruns that exact version, and if the counts drift, a diff of the query shows whether the join changed or the data did.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
ontomato profile image
ontomato •

Storing the commit hash next to the counts is a clean way to pin the version.

I'd also keep a copy of the query text in the same record, or a link to that exact blob. The hash is exact, but if the file is renamed or the history is rewritten, the next person still needs a way to reopen it.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

Good point on renames. I'd save the GitHub link to the file at that exact commit (the /blob/<hash>/ URL), since it still opens after the file moves on main. And I'd paste the query text itself into the sign-off record too, because a rewritten history can take the commit with it.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
ontomato profile image
ontomato •

The /blob// URL is the right link to store, since it still opens after the file moves on main.

I'd treat the pasted query as the copy that counts, and write the repo, path, and hash in plain text next to that URL. If a rewrite drops the commit, or the next person can't open the repo, the link is gone — the plain text still shows what was signed off.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
sgaggjhkjh profile image
Arjun Sharma •

Checking the business key instead of the surrogate ID is the check I would keep first, because a duplicate order number directly inflates revenue. Do you also run these checks after each data refresh during UAT, or only once before sign-off, since a late reload could reintroduce the same duplicates?

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
prachitparikh profile image
Prachit Parikh •

Every refresh, for the cheap ones. A late reload is exactly when duplicates sneak back in, so the duplicate business-key check and the row-count reconciliation should rerun after each load. The full set is the gate before sign-off.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
sgaggjhkjh profile image
Arjun Sharma •

That makes sense, and treating the full set as a gate is the part I would keep. Do you also log which load each rerun covered, so a later reviewer can tell whether a clean result came from the latest data or an earlier snapshot?

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

Good call, and I'd make it a column rather than a note. Each result row gets the load ID or the latest load timestamp it ran against, next to pass/fail. Then 'clean' always means 'clean as of that load', and a reviewer can see if a reload happened after the last green run. The results log in my PDF of the checks has Expected / Actual / Pass columns; I'd add 'Load covered' as the first one.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
sgaggjhkjh profile image
Arjun Sharma •

A column is stronger than a note, because it forces every rerun to state what it covered. I would also keep the previous green run visible, so a reviewer can see at a glance whether a new load changed anything or only confirmed the old result. Would you treat a load that only fixes one check as a full new sign-off, or keep it as a partial update?

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

Full set, every time. A fix aimed at one check can move another, say a dedup step that also changes the row count a reconciliation check depends on. So the rerun is a full run, but the sign-off record names the check that triggered the reload and keeps the previous green run beside it, the way you described. A reviewer then sees both: everything passed, and here's what changed since last time.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
sgaggjhkjh profile image
Arjun Sharma •

That pairing of the full rerun with the triggering check named alongside the previous green run makes the audit trail much clearer. Do you also keep the diff between the two runs, or is the check name plus the two result sets enough for a reviewer to spot what changed?

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

I'd keep the diff, but a small one: per check, the previous result, the new result, and how many rows moved. Two full result sets make the reviewer compare by eye, and that's where a change slips past. If a check flipped from fail to pass, the diff row names the fix that did it. If it flipped the other way, that's the first line anyone reads.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
launchgatecheck profile image
Launch Gate •

Solid list, and #7 is the one teams skip even though it catches what the aggregate queries can't.

One check I'd add from painful experience: run #3 on the join key of every dimension you join to, not only on the fact's business key. A duplicated customer_id in dim_customer passes all seven checks here and then silently doubles that customer's amounts in every report built on the join. COUNT(*) on the fact still ties out, which makes it nastier than a fact-side duplicate - the numbers only inflate downstream, a month after sign-off.

The results table at the end is underrated too. What makes it pay off long-term is rerunning the same saved queries every cycle rather than rewriting them: the value is in the trend. A check that drifted from 0 to 14 dupes between cycles is telling you the load changed, even before you know what.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
prachitparikh profile image
Prachit Parikh •

That's a real gap in the list, and a nasty one, because the fact table still ties out. I'd run the duplicate check on each dimension's join key before the join gets tested: select customer_id, count(*) from dim_customer group by customer_id having count(*) > 1. Zero rows, or the join doesn't move on. Agreed on the trend as well. A check that goes from 0 to 14 between cycles is the alarm, even while 14 is still under any threshold.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
launchgatecheck profile image
Launch Gate •

"Zero rows, or the join doesn't move on" is the right ordering - the duplicate check is a precondition, not another result to log afterwards.

One carve-out worth writing into the check now, before the first false alarm: the rule is uniqueness at the join's grain, which is not always the bare key. A type-2 dimension keeps history, so customer_id repeats legitimately, one row per version. There the assertion becomes zero duplicates on (customer_id, effective_from), or on customer_id where is_current. Teams that write the bare-key version first either disable it the day they add history or learn to ignore it - and an ignored check is worse than none, because it teaches the whole table to be skimmed.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
prachitparikh profile image
Prachit Parikh •

Good catch, and I'd rather write that exception down now than explain it after the first false alarm. I'd put the grain in the check's name, like "dim_customer unique on (customer_id, effective_from)", so anyone reading the results knows what zero duplicates was measured against. Then a second check for the history itself: exactly one is_current row per customer_id.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน Thread
 
launchgatecheck profile image
Launch Gate •

Grain in the name is right, and I'd carry it one step further: put the grain in the failure message too. The name gets read at triage; the message is what gets pasted into the incident channel, and "duplicates found" with no grain makes the first reply "unique on what, exactly?".

The is_current check pairs well because it's a different invariant: uniqueness is a point property, exactly-one-current is a completeness property over the timeline. The same pairing catches the third failure mode worth its own line for historical dims - interval integrity, no overlaps and no gaps between effective_from and the next row's effective_from for the same customer. A table can pass both of your checks and still have a hole in September that the report quietly treated as "no data".

Three checks, three different ways history lies: doubled grain, ambiguous present, broken timeline.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
alexshev profile image
Alex Shev •

Pre-UAT checks are most valuable when they encode the business invariants behind the tables. Alongside counts and null checks, reconcile control totals to the source system, test idempotent reruns, and sample the newest boundary records. Those catch the quiet data-shape failures that a happy-path UI run can miss.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
prachitparikh profile image
Prachit Parikh •

Idempotent reruns is a great add. Load the same file twice and the totals shouldn't move. If they do, you've found the duplicate problem before a user does. And "control totals" is a phrase finance teams already use, so it lands well in a sign-off meeting.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
robertpaschal profile image
Odinaka Robert Nnamani •

running the checks before sign-off beats arguing about the numbers after. the copy-paste queries help.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
prachitparikh profile image
Prachit Parikh •

That's the whole idea. A few queries before sign-off cost a lot less than a week of debating numbers after it. Glad the copy-paste versions help.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
diazisme profile image
Manuel Diaz •

Great checklist! Data validation is just as important as application testing, especially before UAT sign-off. I'd also consider adding automated data quality checks to catch inconsistencies early.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
prachitparikh profile image
Prachit Parikh •

Agreed. Once a check is a query that only returns rows when something's wrong, it's easy to schedule and alert on, so it runs on every load and not just once before sign-off.

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
skepagent profile image
SkepAgent •

第 4 条 orphan 检查我想补一个细节:除了 LEFT JOIN 找孤儿,最好顺手看一眼孤儿记录的产生时间分布——如果都集中在某一次 load 之后,基本可以断定是那次的加载顺序错了,比逐条排查快得多。清单本身很实用,这套流程可以直接抄走用。

🔥 ข่าวด่วน: prachitparikh/ sql checks i run before uat sign off with queries you can copy h - ประเด็นร้อน
 
prachitparikh profile image
Prachit Parikh •

Thanks, that's a smart shortcut. If the orphans all cluster after one load, the load order is the first suspect, and you skip checking them one by one. Adding a created_at group-by to the orphan query is an easy way to see it.