docs/sources/datasources/mssql/annotations/index.md
Annotations overlay event markers on your dashboard visualizations, helping you correlate metric behavior with events like deployments, incidents, or configuration changes. You can use the Microsoft SQL Server data source to create annotation queries that display SQL query results as annotation events.
For general information about annotations, refer to Annotate visualizations.
Before you create MSSQL annotations, ensure you have:
To add a Microsoft SQL Server annotation to your dashboard:
Your annotation query must return columns with specific names. Grafana uses these names to map query results to annotation fields.
| Column | Required | Description |
|---|---|---|
time | Yes | The date/time of the event. Can be a native SQL date/time type or a Unix epoch value in seconds. |
timeend | No | The end time for region annotations. Same format as time. Creates a shaded region instead of a line. |
text | Yes | The event description displayed in the annotation tooltip. |
tags | No | Comma-separated string used for event tags. Tags help categorize and filter annotations. |
Given a table that stores events with Unix epoch timestamps:
CREATE TABLE [events] (
time_sec bigint,
description nvarchar(100),
tags nvarchar(100),
)
Query to display events as annotations:
SELECT
time_sec as time,
description as [text],
tags
FROM
[events]
WHERE
$__unixEpochFilter(time_sec)
ORDER BY 1
The $__unixEpochFilter macro automatically filters events to the dashboard's selected time range.
To display annotations as shaded regions (spanning a duration), include both time and timeend columns:
SELECT
time_sec as time,
time_end_sec as timeend,
description as [text],
tags
FROM
[events]
WHERE
$__unixEpochFilter(time_sec)
ORDER BY 1
datetime columnIf your table uses native SQL datetime or datetime2 columns instead of epoch values:
SELECT
time,
measurement as text,
convert(varchar, valueOne) + ',' + convert(varchar, valueTwo) as tags
FROM
metric_values
WHERE
$__timeFilter(time)
ORDER BY 1
The $__timeFilter macro works with native SQL date/time types and filters to the dashboard time range.
Display deployment events on your graphs:
SELECT
deployed_at as time,
'Deployed ' + version + ' to ' + environment as [text],
environment as tags
FROM
[deployments]
WHERE
$__timeFilter(deployed_at)
ORDER BY 1
Display maintenance windows as shaded regions:
SELECT
start_time as time,
end_time as timeend,
'Maintenance: ' + description as [text],
'maintenance' as tags
FROM
[maintenance_windows]
WHERE
$__timeFilter(start_time)
ORDER BY 1
You can use template variables in your annotation queries to make them dynamic. For example, filter events by a selected server:
SELECT
time_sec as time,
description as [text],
tags
FROM
[events]
WHERE
$__unixEpochFilter(time_sec)
AND server IN ($server)
ORDER BY 1
Use these macros in your annotation queries to filter by the dashboard time range:
| Macro | Description |
|---|---|
$__timeFilter(column) | Filters by time range using a native SQL datetime/datetime2 column. |
$__unixEpochFilter(column) | Filters by time range using a column with Unix epoch timestamps. |
For the full list of available macros, refer to the Microsoft SQL Server query editor.
Follow these best practices when creating Microsoft SQL Server annotations:
$__timeFilter() or $__unixEpochFilter() to limit results to the dashboard time range.text column to make annotations useful at a glance.If your annotations aren't appearing or behaving as expected, refer to Troubleshoot Microsoft SQL Server data source issues for common solutions.