SQL Interview: 42 OPTION LABEL

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.
Section: Developer Level: Medium
Question:
You have a series of very similar SQL queries in an application.
You notice that one of them includes an OPTION LABEL clause.
What would this be used for?
Answer:
OPTION LABEL allows you to apply a label to an instance of a query. That then makes it easy to trace executions of the query using tools like Extended Events or SQL Server Profiler.
2025-05-02