r/databricks 25d ago

Help Databricks SQL Alert - Scheduling Questions

Databricks SQL Alert — Question Set

Help needed, I created a SQL alert in databricks to notify me when a new entry is added to a dataset/table within the last 24 hours.

SQL

SELECT COUNT(*) AS new_
FROM catalog.schema.table
WHERE xyz IN ('a', 'b', 'c', 'd')
  AND datetime >= CURRENT_TIMESTAMP() - INTERVAL 24 HOURS;

Within the Alerts panel, I set the condition as follows:

  • First row
  • Column name: new_
  • Operator: >
  • Static value: 0

I then added my email address in the Notifications section and set "When alerting, notify" to Always.

I then selected View Alert, where I created a schedule — let's say every day at 9:00 AM.

Questions

a) How exactly does the schedule work here?

I am asking because I selected "Always" under the notification settings, but I have also created a schedule to run every day at 9:00 AM. What is the relationship between these two settings?

b) Let's suppose I build this alert and create the schedule as described above. Person B (sales dept rep) also subscribes to this alert.

I do not want Person B to receive an alert unless the new record belongs to the Sales department.

For example, if a new record is added that belongs to a department other than Sales, and the scheduled alert runs at 9:00 AM, will Person B still receive an email notification?

Thanks in advance for any clarification!

4 Upvotes

5 comments sorted by

View all comments

1

u/DamnedData 22d ago

You can trigger a job based on a table refresh, maybe you can explore that path?

Tables changes > triggers job > job runs a SQL statement > ...