UPDATE

Modify existing rows in your tables using SQL UPDATE statements.

Overview

UPDATE modifies existing rows in a table. Always include a WHERE clause to target specific rows — an UPDATE without a WHERE clause updates every row in the table.

Basic Syntax

UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;

Examples

Update a Single Row by ID

UPDATE users SET name = 'Alice Smith', email = '[email protected]' WHERE id = 42;

Update Multiple Rows

UPDATE posts SET is_published = 1 WHERE category = 'announcements';

Update with a Calculated Value

UPDATE products SET price = price * 1.10 WHERE category = 'electronics';

Update with LIMIT

MariaDB supports LIMIT on UPDATE to cap how many rows can be modified in one statement:

UPDATE notifications SET is_read = 1 WHERE user_id = 5 ORDER BY created_at ASC LIMIT 50;

Safety Note

An UPDATE without a WHERE clause will update every row in the table. Always double-check your WHERE clause before running an update, especially in production.

-- This updates ALL rows in the table:
UPDATE users SET is_active = 0;

-- This updates only the intended row:
UPDATE users SET is_active = 0 WHERE id = 42;

Using UPDATE via the API

The CRUD PUT endpoint handles updates with a target ID:

const result = await datasquirel.crud.update({
    dbName: "my_database",
    tableName: "users",
    targetID: 42,
    body: {
        name: "Alice Smith",
        email: "[email protected]",
    },
    apiKey: process.env.DATASQUIREL_API_KEY,
});

Only the fields you include in body are changed — other columns retain their current values.