Basic Update
Update rows with theset() method:
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: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):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 loopsAvoid 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