# ALTER QUERY

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

```sql
ALTER QUERY { query_id | query_name[:query_version] }
  { ADD | DROP } TAG tag_key = 'tag_value'
  [, { ADD | DROP } TAG tag_key = 'tag_value' ]...;
```

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

Modify tags associated with an existing [Streaming or Continuous Query](/overview/core-concepts/queries.md#_streaming_or_continuous_query).

The `ALTER QUERY` statement allows you to add or remove tags from a query. Tags are key-value pairs that can be used for metadata, organization, and filtering purposes.

Queries can only be modified by a [Role](/overview/core-concepts/access-control.md#_role) with appropriate privileges on the query.

### Arguments

#### **query\_id**

Specifies the unique identifier (UUID) of the query to modify. You can find query IDs using the [LIST QUERIES](/reference/sql-syntax/command/list-queries.md) command.

#### **query\_name**

Specifies the name of the query to modify. For case-sensitive names, the name must be wrapped in double quotes, otherwise, the lowercased name will be used.

#### **query\_version**

Specifies the version of the query when using `query_name`. If not provided, the latest version is used.

#### **tag\_key**

Specifies the key name for the tag. Tag keys are string values that identify the tag.

#### **tag\_value**

Specifies the value for the tag. Tag values are string values associated with the tag key.

### Tag Operations

#### `ADD TAG`

Adds a new tag to the query with the specified key-value pair. If a tag with the same key already exists, it will be updated with the new value.

#### `DROP TAG`

Removes the tag with the specified key from the query. The tag value must still be specified in the syntax but is ignored during the operation.

## Examples <a href="#example" id="example"></a>

#### Add tags to a query

Add multiple tags to a query using its ID:

```sql
ALTER QUERY 142ecf31-bc8d-496b-bd0b-28ebb4a8757e 
  ADD TAG 'environment' = 'production',
  ADD TAG 'team' = 'analytics',
  ADD TAG 'cost-center' = 'engineering';
```

#### Add a tag to a query using query name

Add a tag to a query using its name and version:

```sql
ALTER QUERY my_analytics_query:2 
  ADD TAG 'priority' = 'high';
```

#### Remove tags from a query

Remove specific tags from a query:

```sql
ALTER QUERY my_analytics_query 
  DROP TAG 'environment' = 'staging',
  DROP TAG 'deprecated' = 'true';
```

#### Mix add and drop operations

Add some tags while removing others in a single statement:

```sql
ALTER QUERY 142ecf31-bc8d-496b-bd0b-28ebb4a8757e 
  ADD TAG 'environment' = 'production',
  DROP TAG 'environment' = 'staging',
  ADD TAG 'updated_by' = 'admin';
```

## Related Commands

* [LIST QUERIES](/reference/sql-syntax/command/list-queries.md) - List all queries to find query IDs and names
* [DESCRIBE QUERY](/reference/sql-syntax/command/describe-query.md) - View query details including current tags
* [CREATE TABLE AS](/reference/sql-syntax/query/create-table-as.md) - Create streaming queries
* [CREATE MATERIALIZED VIEW AS](/reference/sql-syntax/query/materialized-view/create-materialized-view-as.md) - Create materialized view queries


---

# 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/ddl/alter-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.
