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
syntax.sql
UPDATEtable_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 */ }
);
Reference
Parameters
The executeSql call for an update takes these arguments:
Argument
Type
Description
sqlStatement
String
The UPDATE ... SET ... WHERE ... text, with ? placeholders for dynamic values.
arguments
Array
Values bound to each ? in order—SET values first, then WHERE values (e.g. [name, qty, id]).
successCallback
Function (optional)
Called as (tx, result). Inspect result.rowsAffected.
errorCallback
Function (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.
Result
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.
Property
Type
Meaning after UPDATE
result.rowsAffected
Number
How many rows were updated
result.insertId
Number
Not useful for UPDATE (used after INSERT)
result.rows
SQLResultSetRowList
Empty for UPDATE (no selected rows)
rowsAffected values:
Value
What it means
0
No row matched your WHERE (wrong id or row does not exist). Not an error.
1 or more
That many rows were updated successfully.
Flow
How It Works
A typical single-row update follows these steps:
Open the database with openDatabase(name, version, displayName, size).
Start a transaction: db.transaction(function (tx) { ... }).
Run UPDATE via tx.executeSql(sql, args, success, error).
Check rowsAffected in the success callback.
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;
}
);
});
Try it
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…
Code
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)');
}
);
});
Feature-detectopenDatabase before running any SQL.
Create and seed the table on load.
On button click, run UPDATE ... SET ... WHERE id = ?.
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.
Compatibility
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.
LegacyModern browser support
Google ChromeRemoved ~97+
Removed
Mozilla Firefox—
Never supported
Apple SafariLegacy
Historical / limited
Microsoft EdgeRemoved
Removed (Chromium)
OperaRemoved
Removed (Chromium)
Samsung InternetLegacy
Do not rely on
Internet Explorer—
Not supported
Web SQL UPDATEDeprecated
Bottom line: For updates in new web apps, use IndexedDB update. Keep Web SQL only for maintaining old codebases.
Remember
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.