An on-demand database query or report created by a user in real time, without relying on prebuilt, scheduled report templates.
- Ad hoc queries allow DBAs and analysts to answer one-off questions directly against live or historical data without engaging a report developer.
- In SQL Server environments, ad hoc queries can impact performance if poorly written — consuming excessive CPU, memory, or I/O.
- DBAs should monitor ad hoc query workloads using tools like SQL Server Profiler, Extended Events, or SQL Diagnostic Manager to catch runaway queries.
- Enabling the ‘optimize for ad hoc workloads’ server option in SQL Server reduces plan cache bloat from single-use ad hoc statements.
- Ad hoc reporting capabilities are often requested by business users and data analysts who need flexibility beyond canned reports.
- Related terms: Dynamic SQL, Query Store, Execution Plan
