How to: Cancel a Running Query
After you start to execute a query, you might decide to cancel the query execution before it finishes. The following examples illustrate scenarios in which you might want to cancel a running query:
The query might be taking longer than you expected, which might indicate that the query contains an error or is consuming excessive server resources.
You see the result that you need in the first few rows of the result set and you do not want the query to retrieve additional rows.
You might want to cancel the execution of a script that contains multiple queries. If one query fails to execute successfully, you might want to cancel execution to fix the problem.
To cancel a running query in the Transact-SQL editor
Display the session of the Transact-SQL editor that is executing the query that you want to cancel.
On the Data menu, point to Transact-SQL Editor, and click Cancel Query Execution.
The query execution stops, and the results pane displays any results that have already been returned. The property browser reflects the number of rows that were already retrieved when you canceled the query.
To cancel a running query in the Transact-SQL editor using the toolbar
Display the session of the Transact-SQL editor that is executing the query that you want to cancel.
On the Transact-SQL Editor toolbar, click Cancel Query Execution.
The query execution stops, and the results pane displays any results that have already been returned. The property browser reflects the number of rows that were already retrieved when you canceled the query.
To cancel a running query in the Transact-SQL editor using the shortcut menu
Display the session of the Transact-SQL editor that is executing the query that you want to cancel.
In the Transact-SQL editor, right-click to display the shortcut menu, and click Cancel Query Execution.
The query execution stops, and the results pane displays any results that have already been returned. The property browser reflects the number of rows that were already retrieved when you canceled the query.
To cancel a running query in the Transact-SQL editor using the keyboard
Display the session of the Transact-SQL editor that is executing the query that you want to cancel.
Press ALT+Break.
The query execution stops, and the results pane displays any results that have already been returned. The property browser reflects the number of rows that were already retrieved when you canceled the query.
See Also
Tasks
How to: Start the Transact-SQL Editor
Concepts
Editing Database Scripts and Objects with the Transact-SQL Editor