What you will be able to do
- Explain what a Databricks SQL alert evaluates and the three states an evaluation can end in
- Choose between the first value of a column and an aggregation across all rows for an alert condition
- Set the operator and threshold, test the condition, and handle queries that return no rows
- Schedule an alert and avoid skipped runs caused by the workspace active-run limit
Key concept
Databricks SQL alert — A saved object that runs its own SQL query on a schedule, reduces the result to one value, and compares that value with a threshold. Users or notification destinations are notified when the comparison is met.
1.What an alert evaluates
An alert turns a query into a monitor. It runs on a schedule, checks a condition against the result, and notifies people when the condition holds. Teams use alerts for business KPIs, data quality, cost trends and warehouse health. The common thread is that nobody needs to keep a dashboard open to notice when a number moves.
Every evaluation ends in one of three states. TRIGGERED means the latest run met the condition, OK means it did not, and ERROR means the evaluation itself failed. Current alerts have no UNKNOWN state; that state belonged only to legacy alerts, which still sit on their own tab of the Alerts page.
The alert owns its query. You write the SQL in the alert editor itself, because an existing saved query cannot be reused when creating an alert. Two more constraints shape that SQL. First, alerts do not support queries with parameters, so a query that depends on a query or dashboard parameter has to have its values written into the SQL. Second, the alert runs on a SQL warehouse that you pick in the Compute selector, and the editor shows whether that warehouse is running. See what a SQL warehouse does.
| Editor area | What you set there |
|---|---|
| Query editor | The SQL the alert runs and evaluates |
| Compute | The SQL warehouse that runs the alert query |
| Schedule | How often the alert runs |
| Share | Permissions for others in the workspace |
| Condition | The value, operator and threshold that trigger a notification |
| Notifications | Users or notification destinations to alert, plus an optional repeat frequency |
| Advanced | Notify on OK, empty result state, and the notification template |
Checkpoint 1 of 8· Match them up
You are setting up an alert in the alert editor. Match each editor area to what you configure there.
Tap a term, then the definition that fits it.
You set the threshold in Condition and the destination in Notifications. Special-case behaviour and the message template are in Advanced, the warehouse is in Compute, and how often the alert runs is in Schedule.
“Notifications: Indicate which users or notification destinations should be alerted when the threshold value falls outside of the expected range.”Source: docs.databricks.com
2.Choosing the value the condition checks
A query usually returns many rows, but the condition compares one number with a threshold, so the alert has to reduce the result to a single value. The Condition section gives two ways to do it, and choosing the wrong one gives the wrong answer.
First value of a column reads the chosen column in the top row and ignores every other row. Use it when the query already puts the answer in that row. One case is a query that computes the total itself. Another is a result sorted newest-first, where only the latest hour or day matters. If a query sorts hourly error_count values in descending time order, the first value is the latest hour's count. Summing or averaging the column would mix in all the older hours.
An aggregation across all rows applies a function such as SUM or AVERAGE to one column over the whole result. Use it when the number you care about is spread across rows. If a revenue query returns one row per store, the first value is just one store's revenue. Choosing Sum on revenue gives the daily total across all stores, which is the number to compare with a $50,000 floor. Average divides the total by the number of stores, so it gives a per-store figure and never the total.
The aggregation runs inside the alert, not in your query. The alert wraps your SQL in a common table expression and runs an aggregating query over it. For a query SELECT 1 AS column_name with a SUM aggregation, each run executes WITH q AS (SELECT 1 AS column_name) SELECT SUM(column_name) FROM q. The value that gets evaluated is always decided here: by the query's own SQL plus the Condition settings. The notification template only formats the message after the value has been evaluated. A LIMIT or HAVING written into a template changes nothing about which rows are checked.
Checkpoint 2 of 8· Check yourself
A query returns one row per sales region with an order_count column. The team wants a notification when the combined order count across all regions falls below 2,000. Which Condition setting should the alert use?
The figure the team cares about is spread across rows, so the alert needs an aggregation, and Sum gives the total. First value reads only the top row, and Average gives a per-region mean instead of the total.
“select to set an aggregation across all rows of a single column, such as SUM or AVERAGE”Source: docs.databricks.com
Checkpoint 3 of 8· Check yourself
An alert uses a SUM aggregation on amount. To make the alert compare only the most recent 24 rows against the threshold, an analyst adds LIMIT 24 to the custom notification template. What effect does this have on the value the alert evaluates?
The alert puts the query's own SQL in a CTE and aggregates it, so the template has no part in choosing rows. To limit the rows, put the LIMIT in the alert's query itself.
“The alert wraps the original query text in a common table expression (CTE) and performs a wrapping aggregation query on it”Source: docs.databricks.com
Checkpoint 4 of 8· Exam question
A BI team wants a Databricks SQL alert to fire whenever the total daily revenue reported by a query drops below $50,000, and the underlying query returns one row per store with a revenue column across many stores. Which condition configuration correctly triggers the alert based on the overall daily total rather than any single store's value?
Correct answer: B — Set the alert's Column to revenue, choose an aggregation of Sum across all rows, and set the operator/threshold to less than $50,000, so the alert evaluates the combined daily total.
- A. Evaluating only the first row ignores every other store's revenue, so this setting compares one store's figure to the threshold instead of the overall daily total.
- B. Choosing Sum as the aggregation across all rows adds every store's revenue into a single combined figure, which is exactly what a total-daily-revenue threshold needs to compare against.
- C. Average is not the same operation as Sum; averaging store revenues produces a per-store mean rather than the combined daily total the team wants to threshold against.
- D. Notification templates only format the text of a message after an alert fires; they do not control which rows or aggregation the condition itself evaluates before triggering.
Checkpoint 5 of 8· Exam question
An alert's underlying query returns a result set sorted so that the most recent hourly error_count value appears in the first row, followed by older hourly values in subsequent rows. The analyst wants the alert to evaluate only that most recent hour's count, ignoring the rest of the rows. Which condition setting achieves this?
Correct answer: C — Set the alert's Data Value option to evaluate the first value of the error_count column, so only the top row of the sorted result set is compared against the threshold.
- A. Summing across all rows combines every hour's error count into one total, which still mixes in older rows instead of isolating just the most recent hour's value.
- B. Averaging across all rows blends the newest count together with every older row's count, so it does not isolate the most recent hour on its own.
- C. The first-value setting evaluates only the top row of the query result, which is the most recent hour given the sort order, matching exactly what the team wants.
- D. The notification template only formats the text of an already-fired alert message; a
LIMIT 1placed there has no effect on which row the condition itself compares.
3.Operator, threshold and testing the condition
With the value chosen, you pick a column, a logical operator such as >, and a threshold. The threshold defaults to Static value, a fixed number that you type in. In the webhook payload, a threshold is described as either a value or a query result column. This means one column of the result can serve as the comparison point for another, for example when a query returns both a measurement and the limit it should stay under.
Test condition runs the query and shows whether the alert would trigger on the current data. Use it before saving. You can change the threshold and test again until the alert fires where you expect it to.
A condition looks at one column, so put any logic that spans several columns into the query. In that case the query returns a flag, and the alert triggers when the flag equals 1:
SELECT CASE WHEN drafts_count > 10000 AND archived_count > 5000 THEN 1 ELSE 0 END
FROM (
SELECT sum(CASE WHEN is_archived THEN 1 ELSE 0 END) AS archived_count,
sum(CASE WHEN is_draft THEN 1 ELSE 0 END) AS drafts_count
FROM queries) dataAn alert's status reflects only its most recent run. Take an alert that checks whether cats is above 1500. It stays TRIGGERED for as long as the value stays above 1500, and once the value falls to 1470 it shows OK. That OK does not mean the alert never fired. It only means the latest evaluation did not meet the condition.
Checkpoint 6 of 8· Fill the gap
The alert should fire only when the drafts count is above 10,000 and the archived count is also above 5,000 at the same time. Which keyword completes the query so that it returns 1 only in that case?
SELECT CASE WHEN drafts_count > 10000 ? archived_count > 5000 THEN 1 ELSE 0 END
FROM (
SELECT sum(CASE WHEN is_archived THEN 1 ELSE 0 END) AS archived_count,
sum(CASE WHEN is_draft THEN 1 ELSE 0 END) AS drafts_count
FROM queries) dataA condition can check only one column, so the query combines both checks into a single flag. AND returns 1 only when both counts are over their limits, and the alert then triggers when the value equals 1. OR would fire when either count is over its limit.
Source: docs.databricks.comCheckpoint 7 of 8· Check yourself
Every hour, an alert checks whether error_rate is above 5. On Friday the Alerts page shows its status as OK, and a manager concludes that the error rate never went above 5 that week. How accurate is that conclusion?
Status describes only the most recent evaluation. The alert could have triggered on Tuesday and then shown OK as soon as a later run stopped meeting the condition.
“This doesn't mean that the Alert was not previously triggered. If your "cats" value is now 1470, your alert will show as OK.”Source: docs.databricks.com
4.Empty results and the alert schedule
Sometimes a query returns no rows, and then there is no value to compare. Advanced settings handles this with Empty result state, which sets the status the alert should return when that happens. Set it on purpose. A query such as "orders with a failed payment in the last hour" returns nothing on a good day, and you choose which status that good day reports.
The schedule controls how often all of this runs. Click the calendar icon to open Edit schedule and choose an interval from the drop-down menus, for example every 5 minutes from 0 minutes past the hour. To write the schedule in Quartz cron syntax, select Show cron syntax. Use Run now on the alert page to evaluate the alert immediately, outside its schedule.
By default, a workspace allows 250 alert runs to be active at the same time. When a scheduled alert fires while every run slot is busy, that run is skipped and nothing is evaluated. Look for this in the evaluation history: gaps at a shared schedule time, while a manual Run now of the same alert succeeds. The fix is to stagger the schedules, so alerts run at 01:30, 01:32 and 01:34 rather than all at 01:30. If the workspace still hits the limit regularly, Databricks Support can raise the quota.
Checkpoint 8 of 8· Check yourself
On a normal day, an alert's query "orders with a failed payment in the last hour" returns no rows at all. The team wants to choose the status the alert reports on those days. Which setting controls it?
When a query returns no rows, there is no value to compare with the threshold. Empty result state sets the status the alert returns in that case. Notify on OK only decides whether an OK result sends a notification, and the template only formats the message.
“Empty result state: Set a special status to return when the query returns no results.”Source: docs.databricks.com
Sources2
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/sql/user/alertsOfficial docs
“Evaluations resolve to OK, TRIGGERED, or ERROR.”
↩︎ What an alert evaluates“An existing saved SQL query cannot be reused when creating an alert.”
↩︎ What an alert evaluates - 2.
“Alerts do not support queries with parameters.”
↩︎ What an alert evaluates“Choose the SQL warehouse that runs the alert query.”
↩︎ What an alert evaluates“You can set an alert condition on the first value of a column in the query result”
↩︎ Choosing the value the condition checks“Set the threshold value to Static value 4000. Static value is selected by default.”
↩︎ Operator, threshold and testing the condition“Click Test condition to preview the alert and test whether the alert would trigger with the current data.”
↩︎ Operator, threshold and testing the condition“Empty result state: Set a special status to return when the query returns no results.”
↩︎ Empty results and the alert schedule“Optionally, select the Show cron syntax checkbox to edit the schedule in Quartz Cron Syntax.”
↩︎ Empty results and the alert schedule“Each workspace has a default limit of 250 simultaneous active alert runs.”
↩︎ Empty results and the alert schedule“set an aggregation across all rows of a single column, such as SUM or AVERAGE”
↩︎ Exam trap 1“Notifications: Indicate which users or notification destinations should be alerted when the threshold value falls outside of the expected range.”
↩︎ Checkpoint“select to set an aggregation across all rows of a single column, such as SUM or AVERAGE”
↩︎ Checkpoint“When all run slots are in use and a scheduled alert fires, the alert run is skipped and the alert does not evaluate.”
↩︎ Prediction - 3.
“The alert wraps the original query text in a common table expression (CTE) and performs a wrapping aggregation query on it”
↩︎ Choosing the value the condition checks“your query can implement the alert logic and return a Boolean value for the alert to trigger on”
↩︎ Operator, threshold and testing the condition“The alert wraps the original query text in a common table expression (CTE) and performs a wrapping aggregation query on it”
↩︎ Exam trap 2 - 4.
“The value or query result column that the source is compared against.”
↩︎ Operator, threshold and testing the condition
Also cited
“periodically runs a query, evaluates a condition of its result, and notifies one or more users and/or notification destinations”
↩︎ Key concept“OK means that on the most recent query execution, the Value column did not meet the Condition and Threshold you configured.”
↩︎ Exam trap 3“This doesn't mean that the Alert was not previously triggered. If your "cats" value is now 1470, your alert will show as OK.”
↩︎ Checkpoint