Nested Transactions (Savepoints) in Drizzle ORM

From the Drizzle ORM cheat sheet · Transactions · verified Jul 2026

Nested Transactions (Savepoints)

Use nested transactions that create savepoints for partial rollback.

typescript
await db.transaction(async (tx) => {
  await tx.insert(users).values({
    name: 'Alice',
    email: 'alice@example.com',
  });

  // Nested transaction — creates a SAVEPOINT
  try {
    await tx.transaction(async (tx2) => {
      await tx2.insert(posts).values({
        title: 'First Post',
        authorId: 1,
      });
      // This will rollback only the nested tx
      throw new Error('Oops');
    });
  } catch {
    // Nested tx rolled back, outer tx continues
    console.log('Nested transaction failed');
  }

  // This still commits — Alice is created
  await tx.insert(profiles).values({
    userId: 1,
    bio: 'No posts yet',
  });
});
💡 Nested tx.transaction() creates a SAVEPOINT
⚡ Only nested changes roll back on failure
📌 Outer transaction continues after nested fail
🟢 Wrap nested tx in try/catch to handle errors
transactionnestedsavepoint

Continue with Drizzle ORM

Save the full cheat sheet or work through every related task.

More Drizzle ORM tasks

Back to the full Drizzle ORM cheat sheet