# UPDATE and DELETE

> Change or remove rows of a keyed table, by key or by predicate, optionally within one attribute group.

`UPDATE` and `DELETE` change or remove rows of a keyed table (`UPSERT` or
`VERSIONED`). The examples use the `balances` table.

## UPDATE

`UPDATE <table> SET <column> = <value>, … WHERE <condition> [ATTRIBUTE GROUP <group>]`

- `SET` assigns a literal, an expression, `NULL`, or `DEFAULT` to each named
  column. Columns not named keep their values.
- `WHERE` addresses one row by its complete primary key, or many rows by any
  condition.
- Primary-key columns identify the row and keep their values.

```sql
UPDATE balances
SET amount = 0, updated_at = '2026-10-02 00:00:00.000'
WHERE chain_id = 1 AND address = '0x9c2e4f1a' AND token = 'USDC'
ATTRIBUTE GROUP holding;
```

A `STREAM SELECT` open over `balances` receives the change as one delta.

`DEFAULT` sets a column to its declared default:

```sql
UPDATE balances
SET label = DEFAULT
WHERE chain_id = 1 AND token = 'USDC';
```

## DELETE

`DELETE FROM <table> WHERE <condition>`

`DELETE` writes a tombstone for each matching key: the row disappears from
current reads, every attribute group included, and its history stays readable
`AS OF COMMIT`.

```sql
DELETE FROM balances
WHERE chain_id = 1 AND address = '0x9c2e4f1a' AND token = 'USDC';
```

```sql
DELETE FROM balances
WHERE chain_id = 1 AND amount = 0;
```

A later write to a deleted key starts the row again; the deleted values do not
return. A subscriber of the table receives each delete as one change: the key's
erase.

## Related pages

- [INSERT, UPSERT and REPLACE](/docs/sql/insert)
- [Attribute groups](/docs/concepts/attribute-groups)
- [Transactions](/docs/sql/transactions)

---

Source: https://nyxdb.io/docs/sql/update-delete/
