Update a single record
Change fields on one known record selected by a unique identifier.
Prisma · Function
prisma.model.update() changes one existing record selected by a unique filter and returns the updated record. Its data object can include scalar changes and supported nested relation operations.
Call a model's update method with a unique where filter and a data object containing the fields or nested operations to apply. The operation updates one existing record and returns the resulting record; use updateMany for bulk changes.
prisma.<model>.update({ where: <ModelWhereUniqueInput>, data: <XOR<ModelUpdateInput, ModelUncheckedUpdateInput>> })| Name | Type | Description |
|---|---|---|
where | ModelWhereUniqueInput | Unique filter identifying the existing record to update. |
data | XOR<ModelUpdateInput, ModelUncheckedUpdateInput> | Field values and supported nested operations to apply to the record. |
The updated model record.
data argument contains the model fields to change; optional or defaulted fields may be omitted.const user = await prisma.user.update({
where: { email: "viola@prisma.io" },
data: { name: "Viola the Magnificent" },
});Updates one uniquely identified User record and returns the updated record.
Change fields on one known record selected by a unique identifier.
Modify a parent and supported related records in one query.
update method?Use update when exactly one existing record should be changed. The where argument selects it with a unique filter, while data specifies scalar changes or supported nested operations; the updated record is returned.
Follow-up: How would you update many records? Use updateMany with a filter and data object; it performs a bulk update and returns the number of affected records.
where and data arguments do?where identifies the target record, and data contains the update payload. Fields that are optional or have defaults in the data model can be omitted from the update input.
Follow-up: What is the difference between data and where? data describes changes, whereas where determines which unique record receives them.
update modify related records?A nested update can change related records as part of updating a parent record. This supports composing a parent update with relation changes in one Prisma Client query.
Follow-up: How can related records be updated in bulk? A nested updateMany can update all matching related records for a particular parent.
updateManyupdateManyAndReturnModelWhereUniqueInputModelUpdateInputnested update