# TERMINATE QUERY

## Syntax <a href="#synopsis" id="synopsis"></a>

```sql
TERMINATE QUERY [query_id | query_name[:query_version]];
```

## Description <a href="#description" id="description"></a>

`TERMINATE QUERY` stops and deletes the query specified by `query_id`. Note that this does not delete any entity or relation created by the query.

{% hint style="warning" %}
`TERMINATE QUERY` cannot be undone. Use it with care! When a query is terminated, it is deleted and cannot be restarted. You can only recreate the terminated query by using one of the [Query](/reference/sql-syntax/query.md) statements.
{% endhint %}

See [LIST QUERIES](/reference/sql-syntax/command/list-queries.md) for accessing terminated queries.

Queries are visible only if the current [Access Control](/overview/core-concepts/access-control.md#role) has `USAGE` privileges on them.

### Arguments <a href="#parameters" id="parameters"></a>

#### query\_id

This is the unique identifier of the Query to terminate. See [LIST QUERIES](https://github.com/deltastreaminc/ds-docs-gitbook/blob/main-dcap/reference/sql-syntax/query/list-queries.md) to find out how to list all Queries that the user has access to. The first column (`ID`) in the response corresponds with the `query_id`.

#### query\_name

This is the name of the Query to terminate. See [LIST QUERIES](https://github.com/deltastreaminc/ds-docs-gitbook/blob/main-dcap/reference/sql-syntax/query/list-queries.md) to find out how to list all Queries that the user has access to. The column (`Name`) in the response corresponds with the `query_name`. The `query_version` property disambiguates between multiple queries with the same name.

#### query\_version

This is the version of the Query to terminate. See [LIST QUERIES](https://github.com/deltastreaminc/ds-docs-gitbook/blob/main-dcap/reference/sql-syntax/query/list-queries.md) to find out how to list all Queries that the user has access to. The column (`Version`) in the response corresponds with the `query_version`. If `query_name` is provided without a `query_version`, the latest `query_version` will be used.

## Examples

#### Terminate a Query

The following is an example of how to terminate a Query. Note the `ID` from `LIST QUERIES` is the same as the `query_id` used in `TERMINATE QUERY`.

```sh
demo_db.public/demostore# LIST QUERIES;
+--------------------------------------+-----------+----------+-----------------+---------------+-------------------------------+----------+-------------------------------+-------------------------------+
|  ID                                  |    Name   |  Version |  Intended State |  Actual State |  Query                        |  Owner   |  Created At                   |  Updated At                   |
+======================================+-----------+----------+=================+===============+===============================+==========+===============================+===============================+
| f6a96114-625a-4ea4-a0d9-46b7c5ababbc | demoquery |        1 | running         | running       | CREATE STREAM pageviews2 AS   | sysadmin | 2023-02-08 22:08:25 +0000 UTC | 2023-02-08 22:08:25 +0000 UTC |
|                                      |           |          |                 |               | SELECT * FROM pageviews;      |          |                               |                               |
+--------------------------------------+-----------+----------+-----------------+---------------+-------------------------------+----------+-------------------------------+-------------------------------+

demo_db.public/demostore# TERMINATE QUERY f6a96114-625a-4ea4-a0d9-46b7c5ababbc;
+-------+--------------------------------------+----------+------------------------------------------+
|  Type |  Name                                |  Command |  Summary                                 |
+=======+======================================+==========+==========================================+
| query | f6a96114-625a-4ea4-a0d9-46b7c5ababbc | DROP     | query                                    |
|       |                                      |          | f6a96114-625a-4ea4-a0d9-46b7c5ababbc     |
|       |                                      |          | was marked for termination               |
+-------+--------------------------------------+----------+------------------------------------------+

demo_db.public/demostore# TERMINATE QUERY demoquery:1;
+-------+--------------------------------------+----------+------------------------------------------+
|  Type |  Name                                |  Command |  Summary                                 |
+=======+======================================+==========+==========================================+
| query | f6a96114-625a-4ea4-a0d9-46b7c5ababbc | DROP     | query                                    |
|       |                                      |          | f6a96114-625a-4ea4-a0d9-46b7c5ababbc     |
|       |                                      |          | was marked for termination               |
+-------+--------------------------------------+----------+------------------------------------------+
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.deltastream.io/reference/sql-syntax/query/terminate-query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
