# UPDATE — change items

Change data two ways, by the shape of the `WHERE`. Name the **complete primary key** and it's a native single-item write that runs on the first press. Name anything looser — exactly the shape DynamoDB itself refuses — and it becomes a **preview-first set-based write**: the first Run shows the affected rows, an unchanged second Run applies them, and every write re-checks its predicate atomically.

## Syntax

```sql
UPDATE "table"
SET attr = value [SET attr2 = value2 …]   -- repeated SET; attr ± number arithmetic
[REMOVE attr]                             -- drop an attribute
WHERE key predicates [AND conditions]
[RETURNING ALL OLD * | ALL NEW *]
```

DynamoDB's native clause forms pass through as-is — repeated `SET` assignments, `REMOVE` to drop an attribute, `attr ± number` arithmetic. `RETURNING` echoes the item before or after the write (single-statement writes only). Guide: [Writes & transactions](https://www.kanject.com/docs/dynostudio-partiql-writes/).

## Use cases

### Change one attribute on one item

The everyday fix — promote a user, stamp the moment it happened.

```sql
UPDATE "stage.Users"
SET Role = 'admin'
SET LastSeen = CURRENT_TIMESTAMP
WHERE pk = 'USER#42' AND sk = 'PROFILE'
```

_Executes as:_ UpdateItem · Key: USER#42/PROFILE

- The `WHERE` must name the complete primary key — the editor flags anything looser before it runs (it would become a sweep, below).

_Quote this example:_ https://www.kanject.com/docs/dynostudio-update/#update-one-field

### Increment a counter in place

Arithmetic `SET` compiles to a native `UpdateExpression` — no read-modify-write race.

```sql
UPDATE "stage.Accounts"
SET balance = balance - 100
WHERE accountId = 'A1'
```

_Executes as:_ UpdateItem · UpdateExpression: SET #balance = #balance - :v

_Quote this example:_ https://www.kanject.com/docs/dynostudio-update/#increment-counter

### Drop an attribute

Remove a field entirely — different from setting it to NULL, which stores an explicit null.

```sql
UPDATE "stage.Users"
REMOVE LegacyFlag
WHERE pk = 'USER#42' AND sk = 'PROFILE'
```

_Executes as:_ UpdateItem · UpdateExpression: REMOVE LegacyFlag

_Quote this example:_ https://www.kanject.com/docs/dynostudio-update/#remove-attribute

### See the item you just changed

`RETURNING ALL NEW *` echoes the item as it stands after the write — no second read.

```sql
UPDATE "stage.Users"
SET Role = 'admin'
WHERE pk = 'USER#42' AND sk = 'PROFILE'
RETURNING ALL NEW *
```

_Executes as:_ UpdateItem · ReturnValues: ALL_NEW

- `ALL OLD *` returns the pre-write item instead. Not available inside transactions.

_Quote this example:_ https://www.kanject.com/docs/dynostudio-update/#update-returning

### Sweep a whole set (preview-first)

Archive every dormant account. No key in the `WHERE`, so this runs as a **bulk write**: the first Run previews the matching rows (capped at 1,000), an unchanged second Run writes them.

```sql
UPDATE "stage.Accounts"
SET status = 'archived'
WHERE status = 'dormant'
```

_Executes as:_ Preview first → one UpdateItem per row, each re-checking status = 'dormant' as a ConditionExpression

- Per-item, **not atomic**: if a write fails partway, prior writes stand and the status line reports `applied / skipped / planned`.
- A row that changed since the preview is *skipped and counted*, never blindly overwritten.

_Quote this example:_ https://www.kanject.com/docs/dynostudio-update/#archive-sweep

## Try it

**Try it · UPDATE**

```sql
UPDATE "stage.Users"
SET Role = 'admin'
WHERE pk = 'USER#42' AND sk = 'PROFILE'
RETURNING ALL NEW *
```

_Executes as:_ UpdateItem · stage.Users — A complete-key write — native, single item, first press.

_Run it live in DynoStudio:_ https://www.kanject.com/dynostudio/

> **A sweep is per-item, not a transaction:** A set-based `UPDATE` applies one native write per row. When partial application is unacceptable — money moves, linked records — use a [transaction](https://www.kanject.com/docs/dynostudio-transactions/) instead (all-or-nothing, up to 100 statements).

Related: [Writes & transactions](https://www.kanject.com/docs/dynostudio-partiql-writes/) · [INSERT & upserts](https://www.kanject.com/docs/dynostudio-insert/) · [DELETE](https://www.kanject.com/docs/dynostudio-delete/) · [Transactions](https://www.kanject.com/docs/dynostudio-transactions/).

---
_Source: https://www.kanject.com/docs/dynostudio-update/ · Kanject Docs_
