Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Module

update

Prisma Client’s update() changes one existing record selected by where and returns it. Use updateMany() for bulk changes, or updateManyAndReturn() when the updated objects are needed on supported databases.

How it works

Prisma Client's update() method selects one existing record with a unique where condition, applies the changes in data, and returns the updated record. Use updateMany() when the operation should affect a batch and return only the number of changed records.

Syntax

prisma.<model>.update({ where: <unique selector>, data: <update input> })

Parameters

NameTypeDescription
whereWhereUniqueInputUnique selector identifying the record to update.
dataUpdateInputField assignments and nested relation operations to apply.

Returns

update() returns the updated record; updateMany() returns the number of updated records. updateManyAndReturn() returns the updated records on supported databases.

Key points

  • Use updateMany() for bulk changes; its result reports how many records were updated.
  • Non-unique filters can help enforce permission checks as part of an update.
  • A version field can detect concurrent changes before the update proceeds.

Common mistakes

  • A nested update fails when the related record targeted by the nested operation does not exist.
  • Nested updates must be placed inside a top-level update operation, rather than used as standalone queries.
  • For optional composite types, use upsert instead of update.

Example: Update one record

const updatedUser = await prisma.user.update({
  where: { email: "viola@prisma.io" },
  data: { name: "Viola the Magnificent" },
});

console.log(updatedUser);

Updates the matching user and returns the resulting record.

When to use it

Update a single record

Change fields on one known record selected by a unique identifier or constraint.

Bulk update records

Apply the same field changes to every record matching a filter.

Nested relation updates

Modify related records while updating their parent record.

Optimistic concurrency control

Guard writes against concurrent changes with a version-based filter.

Interview questions

QHow do update() and updateMany() differ?

update() modifies one record selected by where and returns that record. updateMany() applies changes to all matching records and returns the number updated.

Follow-up: When should updateManyAndReturn() be used? Use it when multiple updated objects are needed; the documentation lists PostgreSQL, CockroachDB, and SQLite as supported databases.

QHow do nested updates work?

A nested update changes related records as part of a top-level update. It is only valid within a parent update query.

Follow-up: What happens if the related record is absent? Prisma Client throws an exception rather than silently creating it.

QHow can an update support optimistic concurrency control?

For optimistic concurrency control, include a version field in the filter so the update checks whether the record changed during execution. The documentation also notes that non-unique fields can be used to enforce permissions during an update.

Follow-up: What limitation applies to older Prisma versions? Versions 4.4.0 and earlier cannot filter update operations on non-unique fields.

  • updateMany
  • updateManyAndReturn
  • upsert
  • nested update
  • optimistic concurrency control
  • version field

Source: Prisma Client API (Prisma ORM v7). Checked 2026-10-16.