Skip to main content
Drizzle ORM provides a type-safe API for updating existing records in your database tables.

Basic Update

Update rows with the set() method:
Always include a where() clause unless you intentionally want to update all rows in the table.

Update Multiple Columns

Update several columns at once:

Update with Expressions

Use SQL expressions and column references:

Conditional Updates

Update rows based on multiple conditions:

Update with Returning

Get the updated row(s) back from the database:
.returning() is supported in PostgreSQL, SQLite, and MySQL 8.0+. It’s not available in older MySQL versions.

Update with Joins (PostgreSQL)

Update using data from joined tables:

Bulk Updates

Update multiple rows efficiently:

Update All Rows

Update every row in a table (use with caution):
Omitting the where() clause updates ALL rows. Always double-check before running such queries.

Pattern Matching Updates

Update based on pattern matching:

Null and Not Null Updates

Update based on null values:

Update with Subqueries

Use subqueries to calculate update values:

Type Safety

Drizzle ensures type safety for updates:

Update in Transactions

Update within a transaction for consistency:

Common Update Patterns

1

Toggle Boolean

2

Touch Updated Timestamp

3

Increment Counter

4

JSON Field Update (PostgreSQL)

Performance Tips

Index Your Where Columns

Ensure columns used in WHERE clauses are indexed for faster updates

Batch Updates

Use inArray() to update multiple rows in one query instead of loops

Avoid Full Table Updates

Always use WHERE clauses unless you really need to update all rows

Use Transactions

Wrap related updates in transactions to ensure data consistency

Next Steps

Delete Queries

Learn how to delete data

Select Queries

Query your updated data

Joins

Use joins in your updates

Transactions

Ensure data consistency