SQL Table Row Count Monitor
Scheduled flow that runs a COUNT(*) query against key tables and sends a Teams alert if any table exceeds a defined row threshold. Lightweight monitoring pattern.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
FlowLibs - SQL Table Row Count Monitor is a scheduled Power Automate Cloud Flow that monitors SQL Server table sizes by running COUNT(*) queries against a configurable list of tables. When any table exceeds a defined row count threshold, the flow posts a styled HTML alert to a Microsoft Teams channel with a summary table showing which tables are over the limit.
This is a lightweight monitoring pattern ideal for database administrators and developers who want proactive visibility into table growth without setting up dedicated monitoring infrastructure.
Use Case
Database tables that grow unchecked can cause performance degradation, storage cost increases, and compliance issues. This flow provides a simple, scheduled check that answers the question: "Are any of my key tables getting too large?" Examples include monitoring staging tables that should be periodically purged, audit log tables approaching retention limits, or transaction tables nearing capacity thresholds.
Flow Architecture
Recurrence
RecurrenceRuns on a weekly schedule (Monday, Wednesday, Friday at 8:00 AM EST). Configurable via the trigger settings.
Initialize Variables (8 parallel actions)
Initialize variableInitializes 8 variables: varSqlServer (from env var flowlibs_SqlServerName), varSqlDatabase (from flowlibs_SqlDatabaseName), varTeamsGroupId (from flowlibs_TeamsGroupId), varTeamsChannelId (from flowlibs_TeamsChannelId), varRowCountThreshold (from flowlibs_RowCountThreshold, cast to integer), varTableNames (from flowlibs_SqlTableNames), varAlertBody (empty string, accumulates HTML rows), varThresholdExceeded (false flag for conditional alert).
Split Table Names into Array
ComposeUses split(varTableNames, ',') to convert the comma-separated table list into an iterable array.
Loop Through Each Table
Apply to eachFor each table name in the array: executes a row count query (SQL Server ExecutePassThroughNativeQuery_V2 running SELECT COUNT(*) AS RowCount FROM {tableName}), parses the RowCount value via Compose, then evaluates an If condition comparing the row count against varRowCountThreshold. If exceeded, appends an HTML table row (table name, row count in red, threshold) to varAlertBody and sets varThresholdExceeded to true.
If Any Threshold Exceeded
If conditionChecks the varThresholdExceeded flag after all tables have been checked.
- Build Alert HTML — Compose action assembling a complete HTML alert with header, summary table, and server/database context.
- Post Alert to Teams Channel — Teams PostMessageToConversation sends the styled HTML alert to the configured channel.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SqlServerName | String | <configure> | SQL Server instance name or connection string. Set per tenant. |
| flowlibs_SqlDatabaseName | String | <configure> | Target database name. Set per tenant. |
| flowlibs_TeamsGroupId | String | <configure> | Microsoft 365 Group ID for the target Team. Set per tenant. |
| flowlibs_TeamsChannelId | String | <configure> | Channel ID within the Team for alerts. Set per tenant. |
| flowlibs_RowCountThreshold | String | <configure> | Maximum allowed row count before alerting (cast to integer at runtime). Set per tenant (e.g. 100000). |
| flowlibs_SqlTableNames | String | Orders,Customers,Invoices | Comma-separated list of table names to check. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| SQL Server | shared_sql | ExecutePassThroughNativeQuery_V2 (Executes raw SQL COUNT(*) queries) |
| Microsoft Teams | shared_teams | PostMessageToConversation (Posts HTML alert to a Teams channel) |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Change the recurrence schedule
- Edit the Recurrence trigger to run daily, hourly, or on a different cadence to match how often you want table sizes evaluated.
- Add email notifications alongside Teams
- Add an Outlook SendEmailV2 action inside the "If Any Threshold Exceeded" true branch so a parallel email goes to DBAs or an alerts distribution list.
- Monitor multiple databases
- Wrap the existing logic in an outer ForEach loop over a comma-separated database list (promote a new flowlibs_SqlDatabaseNames env var) so one flow can sweep several databases on the same server.
- Add historical tracking
- Insert each check's results (table name, row count, timestamp) into a Dataverse table or SharePoint list to build a trend log for capacity planning.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Split table list
Converts the comma-separated env var value into an array the ForEach loop can iterate.
EXPR.02Dynamic SQL query
Builds the COUNT(*) statement per table; trim() guards against whitespace from the split.
EXPR.03Parse row count result
Extracts the RowCount column from the first row of the SQL result set.
EXPR.04Threshold comparison
True when the table's row count meets or exceeds the configured threshold.
EXPR.05HTML alert row
Appends one row to the HTML summary table for each table that exceeded its threshold.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.