HTML Web SQL UPDATE

Beginner
8 min read
Updated: Nov 2026
5 examples
Live preview

Definition and Usage

Web SQL lets you change existing rows with a normal SQL UPDATE statement, run through tx.executeSql() inside a transaction. Use SET for the new values and WHERE to target specific rows—then check result.rowsAffected.

Pair this with SELECT to read a row first, and INSERT when the row may not exist yet. For new apps, prefer IndexedDB update.

Deprecated API.

Web SQL is obsolete and removed from modern Chrome. Use this page to maintain legacy code or learn SQL updates. New projects should use IndexedDB.

Related ideas.

UPDATE without WHERE changes every row. Prefer UPDATE over INSERT OR REPLACE when you only need to change some columns on a row that already exists.

Syntax

syntax.sql
UPDATE table_name SET col = ? WHERE condition

In Web SQL, wrap that statement in executeSql with bound arguments:

JS
tx.executeSql(
  'UPDATE items SET name = ?, qty = ? WHERE id = ?',
  [name, qty, id],
  function (tx, result) { /* success */ },
  function (tx, error)  { /* failure */ }
);

Parameters

The executeSql call for an update takes these arguments:

ArgumentTypeDescription
sqlStatementStringThe UPDATE ... SET ... WHERE ... text, with ? placeholders for dynamic values.
argumentsArrayValues bound to each ? in order—SET values first, then WHERE values (e.g. [name, qty, id]).
successCallbackFunction (optional)Called as (tx, result). Inspect result.rowsAffected.
errorCallbackFunction (optional)Called as (tx, error). Return true to roll back the transaction.

Always use WHERE for targeted updates. Bind values with ?—never paste user input into the SQL string.

Return Value

executeSql does not return a useful value itself. On success, your callback receives (tx, result). For UPDATE, use result.rowsAffected to see how many rows were changed.

PropertyTypeMeaning after UPDATE
result.rowsAffectedNumberHow many rows were updated
result.insertIdNumberNot useful for UPDATE (used after INSERT)
result.rowsSQLResultSetRowListEmpty for UPDATE (no selected rows)

rowsAffected values:

ValueWhat it means
0No row matched your WHERE (wrong id or row does not exist). Not an error.
1 or moreThat many rows were updated successfully.

How It Works

A typical single-row update follows these steps:

  1. Open the database with openDatabase(name, version, displayName, size).
  2. Start a transaction: db.transaction(function (tx) { ... }).
  3. Run UPDATE via tx.executeSql(sql, args, success, error).
  4. Check rowsAffected in the success callback.
  5. Handle errors in the error callback (return true to roll back).
JS
db.transaction(function (tx) {
  tx.executeSql(
    'UPDATE contacts SET name = ?, email = ? WHERE id = ?',
    ['Alex Updated', '[email protected]', 1],
    function (tx, result) {
      console.log('Updated', result.rowsAffected);
    },
    function (tx, error) {
      console.error(error.message);
      return true;
    }
  );
});

Live Preview

Seed a contact, update it, read it back, or clear. Status updates below. Many modern browsers no longer support Web SQL—if so, the status box will say so.

Uses a private demo database when Web SQL is available. Prefer IndexedDB for new work.

Status

Checking Web SQL support…

Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor. Demos need a browser that still exposes openDatabase.

Example 1 — Update a Row by Id

Change one contact whose primary key is 1.

JS
db.transaction(function (tx) {
  tx.executeSql(
    'UPDATE contacts SET name = ? WHERE id = ?',
    ['Alex Updated', 1],
    function (tx, result) {
      console.log('Updated', result.rowsAffected, 'row(s)');
    }
  );
});
Try It Yourself

How It Works

  1. Open a transaction on the database.
  2. Run UPDATE ... SET ... WHERE id = ? with bound values.
  3. Log rowsAffected so you know a row was changed.

Example 2 — Check rowsAffected

Zero means “not found”—not a thrown error. Show clear UI feedback.

JS
function updateContact(db, id, name) {
  db.transaction(function (tx) {
    tx.executeSql(
      'UPDATE contacts SET name = ? WHERE id = ?',
      [name, id],
      function (tx, result) {
        if (result.rowsAffected === 0) {
          console.warn('No row with id', id);
        } else {
          console.log('Updated id', id);
        }
      }
    );
  });
}

updateContact(db, 99, 'Missing');
Try It Yourself

How It Works

  1. Pass id and new name into a reusable helper.
  2. Inspect rowsAffected in the success callback.
  3. Warn when zero so the user knows nothing was updated.

Example 3 — Update Multiple Columns

Change several fields in one statement. Bind SET values before the WHERE value.

JS
db.transaction(function (tx) {
  tx.executeSql(
    'UPDATE contacts SET name = ?, email = ? WHERE id = ?',
    ['Sam Lee', '[email protected]', 1],
    function (tx, result) {
      console.log('Updated', result.rowsAffected, 'row(s)');
    }
  );
});
Try It Yourself

How It Works

  1. List each column in the SET clause with its own ?.
  2. Order the args array to match placeholder order (SET first, then WHERE).
  3. Confirm with rowsAffected after success.

Example 4 — Update by Condition

Mark every open task as done with one statement.

JS
db.transaction(function (tx) {
  tx.executeSql(
    'UPDATE tasks SET done = ? WHERE done = ?',
    [1, 0],
    function (tx, result) {
      console.log('Marked', result.rowsAffected, 'task(s) done');
    }
  );
});
Try It Yourself

How It Works

  1. Filter with WHERE done = ? instead of updating one id at a time.
  2. Bind both values (new value, then filter value).
  3. Report how many rows were changed.

Example 5 — Complete HTML Page

Seed a record on load, then update it from a button click.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Web SQL Update Demo</title>
</head>
<body>
  <h1>Web SQL UPDATE</h1>
  <button type="button" id="updateBtn">Update id 1</button>
  <p id="status">Opening…</p>

  <script>
    var statusEl = document.getElementById('status');
    if (!window.openDatabase) {
      statusEl.textContent = 'Web SQL is not available in this browser.';
    } else {
      var db = openDatabase('updateDemoDb', '1.0', 'Demo', 1024 * 1024);
      db.transaction(function (tx) {
        tx.executeSql(
          'CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY, name TEXT, qty INTEGER)'
        );
        tx.executeSql(
          'INSERT OR REPLACE INTO items (id, name, qty) VALUES (?, ?, ?)',
          [1, 'Notebook', 2]
        );
      }, null, function () {
        statusEl.textContent = 'Ready. Click Update.';
      });

      document.getElementById('updateBtn').addEventListener('click', function () {
        db.transaction(function (tx) {
          tx.executeSql(
            'UPDATE items SET name = ?, qty = ? WHERE id = ?',
            ['Notebook Pro', 5, 1],
            function (tx, result) {
              statusEl.textContent = 'Updated ' + result.rowsAffected + ' row (id 1).';
            }
          );
        });
      });
    }
  </script>
</body>
</html>
Try It Yourself

How It Works

  1. Feature-detect openDatabase before running any SQL.
  2. Create and seed the table on load.
  3. On button click, run UPDATE ... SET ... WHERE id = ?.
  4. Show rowsAffected in the status text.

Edge Cases & Pitfalls

Most UPDATE bugs come from a missing WHERE, wrong arg order, or ignoring rowsAffected.

WHERE

No WHERE updates everything

UPDATE items SET qty = 0 changes every row. Always double-check the clause before shipping.

order

Args follow ? order

Put SET values first in the array, then WHERE values. Swapping them updates the wrong fields or ids.

zero

rowsAffected can be 0

A successful callback with zero rows means nothing matched—show a “not found” message.

inject

Bind with ?

Never build SQL with string concatenation from user input. Pass values in the arguments array.

legacy

API may be missing

Feature-detect window.openDatabase. Modern Chrome has no Web SQL—point users to IndexedDB.

Browser Support

Web SQL is a deprecated client-side API. Firefox never shipped it. Chrome removed it (about Chrome 97+). Detect with window.openDatabase before running demos.

✓ Deprecated

Web SQL UPDATE

Educational / legacy only. Prefer IndexedDB put() and cursor update() for new production apps.

Legacy Modern browser support
Google Chrome Removed ~97+
Removed
Mozilla Firefox —
Never supported
Apple Safari Legacy
Historical / limited
Microsoft Edge Removed
Removed (Chromium)
Opera Removed
Removed (Chromium)
Samsung Internet Legacy
Do not rely on
Internet Explorer —
Not supported
Web SQL UPDATE Deprecated

Bottom line: For updates in new web apps, use IndexedDB update. Keep Web SQL only for maintaining old codebases.

Key Takeaways

  • Change a row: UPDATE t SET col = ? WHERE id = ? inside db.transaction().
  • Receipt: read result.rowsAffected in the success callback.
  • Safe params: bind SET and WHERE values with ? in the correct order.
  • Legacy: Web SQL is deprecated—use IndexedDB for new projects.

One line: update with UPDATE t SET ... WHERE ... via executeSql, check rowsAffected, prefer IndexedDB going forward.

Frequently Asked Questions

Open the database with openDatabase(), then call db.transaction(). Inside the transaction, use tx.executeSql() with an UPDATE statement and a WHERE clause. Bind new values and the target id with ? placeholders: UPDATE users SET name = ?, age = ? WHERE id = ?
Standard SQL: UPDATE table_name SET column1 = ?, column2 = ? WHERE condition. Always include a WHERE clause when updating specific rows—without it, every row in the table is updated.
Check result.rowsAffected in the success callback. If it is 0, no row matched your WHERE clause (wrong id, or the row does not exist yet).
Web SQL requires all executeSql calls inside db.transaction(). Transactions keep changes atomic—if a later statement fails, earlier changes in the same transaction can roll back.
Web SQL is deprecated and removed from most modern browsers (including current Chrome). Treat this tutorial as educational for legacy code; use IndexedDB for new projects.
UPDATE changes columns on existing rows matched by WHERE—the row must already exist. INSERT OR REPLACE inserts a new row or replaces the entire row when the primary key exists. Use UPDATE when you only want to change specific fields on a row you know is there.

Next: Web Workers API

Move heavy work off the main thread after you finish Web SQL CRUD.

Web Workers →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful