HTML Web SQL DELETE

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

Definition and Usage

Web SQL lets you remove rows with a normal SQL DELETE statement, run through tx.executeSql() inside a transaction. Target specific rows with WHERE, or empty a table with DELETE FROM table_name (no WHERE—use carefully).

Pair this with SELECT to list rows first, and INSERT to add fresh data afterward. For new apps, prefer IndexedDB delete.

Deprecated API.

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

Related ideas.

DELETE FROM t empties rows but keeps the table. DROP TABLE removes the table itself. Always bind user values with ?—never concatenate SQL strings.

Syntax

syntax.sql
DELETE FROM table_name WHERE condition

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

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

Parameters

The executeSql call for a delete takes these arguments:

ArgumentTypeDescription
sqlStatementStringThe DELETE FROM ... WHERE ... text, with ? placeholders for dynamic values.
argumentsArrayValues bound to each ? in order—e.g. [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 deletes. 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 DELETE, use result.rowsAffected to see how many rows were removed.

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

rowsAffected values:

ValueWhat it means
0No row matched your WHERE (wrong id or already deleted). Not an error.
1 or moreThat many rows were removed successfully.

How It Works

A typical single-row delete follows these steps:

  1. Open the database with openDatabase(name, version, displayName, size).
  2. Start a transaction: db.transaction(function (tx) { ... }).
  3. Run DELETE 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(
    'DELETE FROM contacts WHERE id = ?',
    [1],
    function (tx, result) {
      console.log('Deleted', result.rowsAffected);
    },
    function (tx, error) {
      console.error(error.message);
      return true;
    }
  );
});

Live Preview

Seed a sample row, then delete it or clear the table. 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 — Delete a Row by Id

Remove the item whose primary key is 1.

JS
db.transaction(function (tx) {
  tx.executeSql(
    'DELETE FROM items WHERE id = ?',
    [1],
    function (tx, result) {
      console.log('Deleted', result.rowsAffected, 'row(s)');
    }
  );
});
Try It Yourself

How It Works

  1. Open a transaction on the database.
  2. Run DELETE ... WHERE id = ? with [1] bound safely.
  3. Log rowsAffected so you know a row was removed.

Example 2 — Check rowsAffected

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

JS
function deleteItem(db, id) {
  db.transaction(function (tx) {
    tx.executeSql(
      'DELETE FROM items WHERE id = ?',
      [id],
      function (tx, result) {
        if (result.rowsAffected === 0) {
          console.warn('No row with id', id);
        } else {
          console.log('Removed id', id);
        }
      }
    );
  });
}

deleteItem(db, 99);
Try It Yourself

How It Works

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

Example 3 — Delete All Rows

Omit WHERE to empty the table. The table structure stays. Confirm in the UI first.

JS
db.transaction(function (tx) {
  tx.executeSql(
    'DELETE FROM items',
    [],
    function (tx, result) {
      console.log('Cleared', result.rowsAffected, 'row(s)');
    }
  );
});
Try It Yourself

How It Works

  1. Run DELETE FROM items with no WHERE.
  2. Pass an empty args array when there are no ? placeholders.
  3. Use rowsAffected to report how many rows were wiped.

Example 4 — Delete by Condition

Remove every completed task with one statement.

JS
db.transaction(function (tx) {
  tx.executeSql(
    'DELETE FROM tasks WHERE done = ?',
    [1],
    function (tx, result) {
      console.log('Removed', result.rowsAffected, 'completed task(s)');
    }
  );
});
Try It Yourself

How It Works

  1. Filter with WHERE done = ? instead of deleting one id at a time.
  2. Bind 1 (or your “done” flag value) safely.
  3. Report how many completed rows were removed.

Example 5 — Complete HTML Page

Seed a record on load, then delete 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 Delete Demo</title>
</head>
<body>
  <h1>Web SQL DELETE</h1>
  <button type="button" id="deleteBtn">Delete 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('deleteDemoDb', '1.0', 'Demo', 1024 * 1024);
      db.transaction(function (tx) {
        tx.executeSql('CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY, value TEXT)');
        tx.executeSql('INSERT OR REPLACE INTO items (id, value) VALUES (?, ?)', [1, 'Sample']);
      }, null, function () {
        statusEl.textContent = 'Ready. Click Delete.';
      });

      document.getElementById('deleteBtn').addEventListener('click', function () {
        db.transaction(function (tx) {
          tx.executeSql(
            'DELETE FROM items WHERE id = ?',
            [1],
            function (tx, result) {
              statusEl.textContent = 'Deleted ' + 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 DELETE ... WHERE id = ?.
  4. Update the status text with rowsAffected.

Edge Cases & Pitfalls

Most DELETE bugs come from a missing WHERE, unbound input, or ignoring rowsAffected.

WHERE

No WHERE deletes everything

DELETE FROM items wipes every row. Always double-check the clause before shipping.

inject

Bind with ?

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

zero

rowsAffected can be 0

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

tx

Must use a transaction

All executeSql calls belong inside db.transaction() (or readTransaction for reads).

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 DELETE

Educational / legacy only. Prefer IndexedDB store.delete() and clear() 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 DELETE Deprecated

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

Key Takeaways

  • One row: DELETE FROM t WHERE id = ? inside db.transaction().
  • Receipt: read result.rowsAffected in the success callback.
  • Safe params: bind values with ?—never concatenate user input.
  • Legacy: Web SQL is deprecated—use IndexedDB for new projects.

One line: delete with DELETE FROM t 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 DELETE FROM table_name WHERE condition. Bind filter values with ? placeholders: DELETE FROM items WHERE id = ?
Standard SQL: DELETE FROM table_name WHERE condition. Always use WHERE when deleting specific rows—DELETE FROM table_name without WHERE removes every row in the table.
Check result.rowsAffected in the success callback. If it is 0, no row matched your WHERE clause (wrong id or already deleted).
Web SQL requires all executeSql calls within db.transaction(). Transactions keep operations atomic—if a related statement fails, changes can roll back together.
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.
No. Once a transaction commits, deleted rows are gone unless you kept a backup or can re-fetch from a server. Confirm destructive actions in your UI before deleting.

Next: Web SQL INSERT

Add new rows with INSERT INTO after you clear or delete old data.

Insert tutorial →

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