Working with Update Operations

1. Updating Single Record

await prisma.user.update({
  where: { id: 1 },
  data: { name: "Alice" }
});
AspectDetail
WhereMust target unique field
ErrorP2025 if not found

2. Updating Multiple Records

const res = await prisma.post.updateMany({
  where: { authorId: 1, published: false },
  data: { published: true }
});
console.log(res.count);
AspectDetail
ReturnsCount of modified rows
No relationsCannot nest writes

3. Upserting Records

await prisma.user.upsert({
  where: { email: "a@b.io" },
  create: { email: "a@b.io", name: "Alice" },
  update: { name: "Alice" }
});
BlockUse
whereUnique match
createInputs when not found
updateInputs when found

4. Using Where Clause Filters

Update VariantWhere Type
updateUnique only
updateManyAny filter

5. Updating Nested Relations

await prisma.user.update({
  where: { id: 1 },
  data: {
    posts: {
      update: { where: { id: 5 }, data: { published: true } },
      create: { title: "New" },
      delete: { id: 8 }
    }
  }
});
OpEffect
update / updateManyModify children
upsertConditional create
delete / deleteManyRemove

6. Incrementing Numeric Fields

await prisma.post.update({
  where: { id: 1 },
  data: { views: { increment: 1 } }
});
OperatorSQL
incrementviews = views + n
AtomicSafe under concurrent writes

7. Decrementing Numeric Fields

OperatorSQL
decrementfield = field - n

8. Multiplying Numeric Fields

OperatorSQL
multiplyfield = field * n

9. Dividing Numeric Fields

OperatorSQL
dividefield = field / n

10. Setting Fields to Null

await prisma.user.update({ where: { id: 1 }, data: { deletedAt: null } });
ConstraintDetail
Optional onlyRequired fields reject null
JSONUse Prisma.JsonNull