> ## Documentation Index
> Fetch the complete documentation index at: https://docs.narrative.io/llms.txt
> Use this file to discover all available pages before exploring further.

# UPDATE

> Reference for the UPDATE statement

The `UPDATE` statement modifies existing rows in a dataset. Each `UPDATE` assigns new values to one or more columns, optionally filtered by a `WHERE` clause.

<Note>
  UPDATE runs against datasets you own. To update rows during a materialized view refresh, use the [MERGE ON clause](/guides/nql/incremental-upserts) inside `CREATE MATERIALIZED VIEW` instead.
</Note>

## Syntax

```sql theme={null}
UPDATE table_reference
SET
  column1 = expression1
  [, column2 = expression2, ...]
[WHERE condition]
```

* The `SET` clause lists column assignments. The right-hand side of each assignment can be any NQL expression valid for the target column's [data type](/nql/data-types), including references to other columns in the same row.
* The `WHERE` clause is optional. If omitted, **every row in the dataset is updated** — include a `WHERE` clause unless that is the intended behavior.
* The `SET` expressions and the `WHERE` condition can reference only the target dataset. Subqueries that read from another dataset (for example, `WHERE id IN (SELECT id FROM company_data."456")`) are not supported.

## Examples

**Update a single column with a literal:**

```sql theme={null}
UPDATE company_data."123"
SET status = 'archived'
WHERE user_id = 42
```

**Update multiple columns using an expression:**

```sql theme={null}
UPDATE company_data."123"
SET
  email = LOWER(email),
  last_updated_at = CURRENT_TIMESTAMP
WHERE email IS NOT NULL
```

**Conditional update across many rows:**

```sql theme={null}
UPDATE company_data.pipeline_log
SET status = 'stale'
WHERE
  status = 'created'
  AND created_at < CURRENT_TIMESTAMP - INTERVAL '30' DAY
```

## Execution context

UPDATE statements can run in two places:

| Execution surface                                                                      | When to use                                         |
| -------------------------------------------------------------------------------------- | --------------------------------------------------- |
| NQL query endpoint                                                                     | Ad-hoc updates from an API client or Data Studio    |
| [`ExecuteDml` workflow task](/guides/workflows/workflow-orchestration#supported-tasks) | Scheduled or event-driven updates inside a workflow |

<Warning>
  Running UPDATE without a `WHERE` clause modifies every row in the target dataset. Review the statement — or run the corresponding `SELECT` with the same predicate first — before executing.
</Warning>

***

## Related content

<CardGroup cols={2}>
  <Card title="INSERT" icon="plus" href="/nql/commands/insert">
    Add rows to a dataset
  </Card>

  <Card title="DELETE" icon="trash" href="/nql/commands/delete">
    Remove rows from a dataset
  </Card>

  <Card title="Incremental Upserts with MERGE ON" icon="code-merge" href="/guides/nql/incremental-upserts">
    Update or insert rows during materialized view refresh
  </Card>

  <Card title="ExecuteDml workflow task" icon="diagram-project" href="/guides/workflows/workflow-orchestration#supported-tasks">
    Run DML statements from a workflow
  </Card>
</CardGroup>
