How do you monitor freshness and row counts on SQL Server tables?

DataKitchen's open-source DataOps TestGen, a data observability tool, monitors freshness and row counts on SQL Server tables and alerts when a table stops changing or its count leaves the expected range. It compares key-column hashes between runs and logs each row count. In T-SQL, sys.partitions gives approximate row counts and MAX of a load-date column gives freshness.

Key points

  • By hand, sys.partitions holds an approximate row count per partition, and summing rows where index_id is 0 or 1 gives each table's count without scanning it.
  • sys.dm_db_index_usage_stats shows each index's last user update, but its counters reset when SQL Server restarts and reading it needs server-state permission, so a load-date column is a sturdier freshness signal.
  • A row count is only meaningful against history: keep a dated log, compare today's count with the average of recent captures, and alert on large moves either way.
  • Two questions catch broken loads before anyone opens a report: did the table change when it should have, and by about the usual amount?
A SQL Server database beside a daily row-count chart whose last point drops out of its expected range and is flagged amber
A row count only means something against its own history.

Row counts

sys.partitions holds a row count per partition. Index 0 is a heap and index 1 a clustered index, so summing those gives each table’s count without a scan:

SELECT s.name AS schema_name,
       t.name AS table_name,
       SUM(p.rows) AS row_count
FROM sys.tables AS t
JOIN sys.schemas AS s ON s.schema_id = t.schema_id
JOIN sys.partitions AS p ON p.object_id = t.object_id AND p.index_id IN (0, 1)
GROUP BY s.name, t.name
ORDER BY row_count DESC;

Microsoft documents sys.partitions row counts as approximate. They’re accurate enough for trend monitoring. Use COUNT(*) where you need the exact figure.

Freshness

The sturdy signal is a column your load writes, such as LoadedAt:

SELECT MAX(LoadedAt) AS newest_row,
       DATEDIFF(MINUTE, MAX(LoadedAt), SYSUTCDATETIME()) AS minutes_old
FROM dbo.FactSales;

Without one, sys.dm_db_index_usage_stats records the last user update per index:

SELECT OBJECT_SCHEMA_NAME(us.object_id) AS schema_name,
       OBJECT_NAME(us.object_id) AS table_name,
       MAX(us.last_user_update) AS last_write
FROM sys.dm_db_index_usage_stats AS us
WHERE us.database_id = DB_ID()
GROUP BY us.object_id;

Two catches: its counters reset when SQL Server restarts, so “no update” can mean “restarted,” and reading it needs server-state permission, which many DBAs won’t grant a monitoring login.

History and alerts

A count means nothing alone. Create a history table once:

CREATE SCHEMA dq;
GO
CREATE TABLE dq.row_count_history (
    captured_at datetime2(0) NOT NULL DEFAULT SYSUTCDATETIME(),
    schema_name sysname NOT NULL,
    table_name  sysname NOT NULL,
    row_count   bigint  NOT NULL
);
GO

Then schedule this INSERT as a daily SQL Server Agent job:

INSERT INTO dq.row_count_history (schema_name, table_name, row_count)
SELECT s.name, t.name, SUM(p.rows)
FROM sys.tables AS t
JOIN sys.schemas AS s ON s.schema_id = t.schema_id
JOIN sys.partitions AS p ON p.object_id = t.object_id AND p.index_id IN (0, 1)
GROUP BY s.name, t.name;

Then flag tables whose latest count moved more than 20% from the average of the previous seven captures:

WITH h AS (
    SELECT schema_name, table_name, captured_at, row_count,
           AVG(CAST(row_count AS float)) OVER (
               PARTITION BY schema_name, table_name ORDER BY captured_at
               ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING) AS prior_avg,
           ROW_NUMBER() OVER (
               PARTITION BY schema_name, table_name ORDER BY captured_at DESC) AS rn
    FROM dq.row_count_history
)
SELECT schema_name, table_name, row_count, prior_avg
FROM h
WHERE rn = 1 AND prior_avg > 0
  AND ABS(row_count - prior_avg) / prior_avg > 0.20;

This works for a handful of tables. It still needs a write-enabled schema in the database and an Agent job per server, and past a handful, one 20% threshold is wrong for some tables: too tight for a staging table that’s truncated nightly, too loose for a dimension that should never shrink.

How DataOps TestGen monitors tables

TestGen’s monitors replace the history table and the threshold:

MonitorHow it works
FreshnessCompares a fingerprint (hash) of key columns with the previous run and records the minutes since the last change; data profiling picks the columns
VolumeRecords each run’s row count and predicts the expected range with a model trained over about 30 runs
SchemaReports every added, dropped, or changed table and column
MetricTracks a SQL expression you write, such as daily revenue

TestGen creates nothing in your SQL Server database. It runs on its own TestGen server with its own application database, where it stores monitor history. Its SQL Server login needs SELECT on the monitored tables, which includes table data, because freshness fingerprints read key-column values.

Monitors alert where your team already works: email, Slack, Microsoft Teams, or a webhook. The docs suggest running monitors at roughly twice the rate your data changes. TestGen also generates tests from a profile of each table, so you review a baseline instead of writing one by hand. Its UI shows profiles, tests, monitors, and results to engineers and business users alike. Its MCP server has 122 tools, so an AI assistant such as Claude Code can run profiles, generate tests, and read results under your own TestGen role.

Open-source TestGen is free for one user, one connection, and one project. Past that, TestGen Enterprise lists at $100 per user and $100 per connection per month. Start at the SQL Server install page, and see the SQL Server setup answer for the grants.

Process observability

Row counts and freshness tell you what happened to a table. They don’t tell you how the process that fills it ran. We call that process observability: it watches the jobs that make the data, meaning the ETL runs, model runs, and report refreshes across every tool, and flags errors, bottlenecks, and late arrivals.

All the other data observability tools miss process observability. You can have perfect data, but if the engines that run your ETL, your models, or your reports fail or run late, your customers are not going to be happy. DataOps Process Observability is where DataKitchen delivers it. DataOps Process Observability is open source under Apache 2.0, with the UI, event ingestion API, and integration agents. Enterprise is a flat $100 per month per user and per agent. For how the wider field compares, see the best data observability tools in 2026.

A nightly load passes its data tests, the model refresh does not run, the dashboard shows yesterday, and the customer is not happy
Perfect data does not help when the job that uses it never ran. From the best data observability tools in 2026.

Frequently asked questions

Short answers to the follow-up questions people ask next.

What's the fastest way to get row counts for every SQL Server table?

Sum the rows column of sys.partitions for index_id 0 or 1, joined to sys.tables and sys.schemas. It reads catalog metadata instead of scanning tables, so it stays fast as tables grow. Microsoft describes the count as approximate. Use COUNT(*) on the few tables where you need the exact figure.

How do I tell when a SQL Server table was last updated?

Best: a load-date or modified-date column, and MAX of it. Without one, sys.dm_db_index_usage_stats records each index's last user update, but its counters reset when the instance restarts and reading it needs server-state permission. Change tracking or temporal tables also record changes, if they're already turned on.

How much should a row count change before I alert?

It depends on the table, which is why fixed thresholds go noisy. A daily-append fact table should grow by roughly the same amount each day; a dimension should barely move. Start by comparing with the average of the last seven captures and alerting at 20%, then tune per table, or use a monitor that learns each table's pattern.

Does TestGen create anything in my SQL Server database to monitor it?

No. TestGen runs only SELECT statements and stores monitor history in its own application database on the TestGen server. Its SQL Server login needs SELECT on the monitored tables, which includes table data, because freshness fingerprints read key-column values. It also reads sys.objects and sys.partitions, which database users can read by default.

What is process observability, and why do table monitors miss it?

Process observability is watching the jobs that make the data, meaning the ETL runs, model runs, and report refreshes across every tool, and flagging errors, bottlenecks, and late arrivals. Table monitors for freshness, row counts, and schema watch the data after it lands, so they can't show how the process that produced it ran. All the other data observability tools miss process observability.

Try it on your own data

DataOps TestGen is free and open source. Profile a table and generate its tests this afternoon.