"I want to know immediately if sales drop more than 20% day-over-day." "I want an alert when the ETL ingestion row count is zero." Anomaly detection on business metrics like this is exactly what Databricks SQL Alerts are for. You set a condition on a SQL query's result and have it auto-notify Email, Slack, Webhook, etc. when the condition is met. This article walks through creating an Alert, designing the query, configuring destinations, and choosing between Alerts and Jobs Notifications.
A SQL Alert is made up of three components:
An Alert runs the query on a schedule and evaluates the condition. It sends notifications while the condition is met and stops once the condition is no longer satisfied.
In the Databricks SQL Editor, write a query that returns the metric you want to monitor. The Alert condition evaluates the first row / first column of the query result, so the query should be designed to return a single numeric value.
-- 例1: 直近1時間のエラー件数を監視
SELECT COUNT(*) AS error_count
FROM catalog.schema.application_logs
WHERE log_level = 'ERROR'
AND event_time > CURRENT_TIMESTAMP() - INTERVAL 1 HOUR;
-- 例2: 日次ETLの取込件数がゼロかを監視
SELECT COUNT(*) AS ingested_rows
FROM catalog.schema.daily_ingestion_log
WHERE ingestion_date = CURRENT_DATE();
-- 例3: 売上の前日比を監視
SELECT
(today.total_sales - yesterday.total_sales) / yesterday.total_sales * 100
AS daily_change_pct
FROM (
SELECT SUM(amount) AS total_sales
FROM catalog.schema.sales
WHERE order_date = CURRENT_DATE()
) today
CROSS JOIN (
SELECT SUM(amount) AS total_sales
FROM catalog.schema.sales
WHERE order_date = CURRENT_DATE() - INTERVAL 1 DAY
) yesterday;In the Databricks SQL UI, open the "Alerts" section, create a new Alert, and configure the following:
| Setting | Description | Example |
|---|---|---|
| Query | Select the query to evaluate | daily_error_count |
| Trigger when | Condition type (above / below / equals) | above (when exceeded) |
| Threshold | Threshold value | 100 |
| Column | Column to evaluate | error_count |
| Refresh | Evaluation interval | Every 15 minutes |
| Notification frequency | How often notifications are sent | Just once (first time only) / Every time (every evaluation) |
Notification frequency matters. With "Just once," you get a notification only the first time the condition is met; you are not re-notified while the condition continues. If the condition clears and then triggers again, you get re-notified. With "Every time," you get a notification every time the condition is evaluated as true.
Configure where notifications are sent when the Alert is triggered.
| Destination | How to configure | Use case |
|---|---|---|
| Specify a workspace user's email address | Basic notifications for small teams | |
| Slack | Register a Slack Webhook as an Alert Destination | Real-time notifications to a shared team channel |
| Webhook (generic) | Register an HTTPS endpoint as an Alert Destination | Custom automation (Lambda / Cloud Functions, etc.) |
| PagerDuty | Register a PagerDuty Integration Key as an Alert Destination | Critical alerts that require on-call response |
Email can go directly to Databricks users, but Slack, Webhook, and PagerDuty require an administrator to set up an "Alert Destination" in advance.
The JSON payload sent to the Webhook includes the following fields:
{
"alert_id": "abc-123",
"alert_name": "daily_error_count_high",
"alert_state": "triggered",
"alert_url": "https://workspace.databricks.com/sql/alerts/abc-123",
"query_name": "daily_error_count",
"query_url": "https://workspace.databricks.com/sql/queries/xyz-456",
"column": "error_count",
"value": 152,
"threshold": 100,
"condition": "above"
}-- テーブルの最終更新からの経過時間(時間単位)
SELECT
TIMESTAMPDIFF(HOUR, MAX(updated_at), CURRENT_TIMESTAMP()) AS hours_since_update
FROM catalog.schema.fact_orders;
-- Alertの条件: hours_since_update > 4(4時間以上未更新で通知)-- NULL率が閾値を超えたら通知
SELECT
COUNT(CASE WHEN customer_id IS NULL THEN 1 END) * 100.0 / COUNT(*)
AS null_rate_pct
FROM catalog.schema.transactions
WHERE transaction_date = CURRENT_DATE();
-- Alertの条件: null_rate_pct > 5(NULL率5%超で通知)-- 日次DBU消費量が直近7日平均の1.5倍を超えたら通知
WITH daily AS (
SELECT usage_date, SUM(usage_quantity) AS daily_dbu
FROM system.billing.usage
WHERE usage_date >= CURRENT_DATE() - INTERVAL 8 DAY
GROUP BY usage_date
)
SELECT
MAX(CASE WHEN usage_date = CURRENT_DATE() THEN daily_dbu END)
/ AVG(CASE WHEN usage_date < CURRENT_DATE() THEN daily_dbu END) AS ratio
FROM daily;
-- Alertの条件: ratio > 1.5| Aspect | SQL Alert | Job Notification (email_notifications) |
|---|---|---|
| Trigger condition | When the query result satisfies the threshold condition | When the job execution state changes (success / failure / start) |
| Primary use case | Business metrics anomaly detection | Pipeline operational monitoring |
| Evaluation timing | Scheduled execution (every 1 minute to several hours) | Per job run (real time) |
| Custom logic | Freely expressible in SQL | Fixed patterns (on_start / on_success / on_failure) |
| Destinations | Email / Slack / Webhook / PagerDuty | Email (API-defined) / Webhook (task-defined) |
| Compute | SQL Warehouse (started when the Alert runs) | Depends on the job's compute |
| Who configures it | Analyst / BI team | Data engineer |
Data Analyst Associate
問題 1
A data analyst wants to monitor the daily ETL pipeline's ingestion count and automatically notify the team's Slack channel when the count is zero. Using only Databricks SQL features, which is the most appropriate approach?
正解: B
SQL Alerts let you set a condition on a SQL query result (= 0 here) and auto-notify an Alert Destination (Slack) when the condition is met. Visual dashboard checking is not automation, and Job Notifications report on job state, not on the ingestion count. A Notebook implementation would work, but it does not satisfy the "Databricks SQL features only" constraint.
Are SQL Alerts evaluated even when the Warehouse is stopped?
No. A SQL Alert starts the SQL Warehouse, runs the query, and evaluates the result when its schedule fires. If the Warehouse is stopped, it is started automatically — but if Auto Stop is too short, you pay a startup cost on every evaluation. It is important to tune the Alert evaluation frequency and the Warehouse Auto Stop setting together.
What needs to be configured on the Slack side to send Slack notifications from a SQL Alert?
On the Slack side, you need to set up an Incoming Webhook or a Slack App. On the Databricks side, add Slack as an Alert Destination and register the Webhook URL. The notification message automatically includes the Alert name, the triggered value, and the evaluation timestamp. Custom message templates are also supported.
How should I choose between SQL Alerts and the Jobs API email_notifications?
SQL Alerts notify you when a query result meets a specific condition (e.g. sales fell below a threshold, error count spiked). Jobs API email_notifications notify you when a job's execution state changes (e.g. the job failed or timed out). Use the former for business metrics monitoring and the latter for pipeline operational monitoring.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Databricks Certifications: All 7 Exams, Difficulty & Study Plan (2026)
Complete guide to all 7 Databricks certifications — Data Eng...
Databricks Exam Difficulty Ranking: All 7 Certs Compared (2026)
Every Databricks certification ranked by difficulty, with st...
Databricks Study Guide: Fastest Pass Route & Time Estimates (2026)
How to pass Databricks certifications efficiently. Official ...
Databricks Data Engineer Associate: Complete Guide (2026)
Domain-by-domain breakdown of the Databricks Certified Data ...
Databricks Data Engineer Professional: Complete Guide (2026)
Tactics for the Databricks Certified Data Engineer Professio...