# Query SQL execution records

Query SQL execution records by condition to locate executions that require further investigation. To actively submit or cancel SQL, or obtain the result of an execution, see [Execute SQL and manage SQL metadata](../data-processing/sql-execution-metadata.md).

## Prerequisites

Prepare credentials that can access the target workspace. For service endpoints, authentication, and general request formats, see [Prepare to call an API](../../api-call-basics.md).

To narrow the query, prepare known filters such as execution, workspace, or time. The available conditions are defined by the action page.

## Call sequence

1. View the SQL history overview or SQL execution records for the investigation scope, then locate the target execution in the returned records.
2. To inspect the statement text, status, duration, error, or execution plan, record the statement ID and execution time, then view execution details or the execution profile.
3. To inspect the execution status or result, open the SQL execution scenario and use the corresponding status or result operation.

## API operations

| What you need to do | API operation | Use it when |
| --- | --- | --- |
| View the SQL history overview | [Get the SQL history overview](../../../../reference/api/ai-studio/monitoring/get-sql-history-overview.md) | Aggregate execution-record totals by time range and SQL source. |
| Query SQL execution records | [List SQL execution records](../../../../reference/api/ai-studio/monitoring/list-sql-execution-records.md) | Browse or filter existing SQL execution records. |
| View SQL execution details | [Get SQL execution details](../../../../reference/api/ai-studio/monitoring/get-sql-execution-details.md) | You have the statement ID and execution time and need complete execution information. |
| View the SQL execution profile | [Get the SQL execution profile](../../../../reference/api/ai-studio/monitoring/get-sql-execution-profile.md) | You have the statement ID and execution time and need to analyze execution steps and resource use. |

## Confirm the result

Check that the overview or returned records cover the target scope and execution. After locating the target, use [Get SQL execution details](../../../../reference/api/ai-studio/monitoring/get-sql-execution-details.md), [get the SQL execution profile](../../../../reference/api/ai-studio/monitoring/get-sql-execution-profile.md), [get execution status](../../../../reference/api/ai-studio/data-processing/sql-execution/get-execution-status.md), and [get execution result](../../../../reference/api/ai-studio/data-processing/sql-execution/get-execution-result.md) to continue confirming the execution and result.

## Next steps

- [Execute SQL and manage SQL metadata](../data-processing/sql-execution-metadata.md)
- [Query operation logs](operation-logs.md)
