sqlcmd.net validated sql reference
beginner deleting MySQL MariaDB SQL Server PostgreSQL SQLite

Delete Rows

Remove matching rows with `DELETE`, then query the remaining table contents.

Docker-validated Not currently validation-green

Delete one row by id

As with UPDATE, the important safety habit is to make the WHERE clause precise before running the statement.

MySQL MariaDB SQLite
Engine-specific syntax
Setup
CREATE TABLE logs (id INT, level VARCHAR(20));

INSERT INTO
  logs (id, level)
VALUES
  (1, 'info'),
  (2, 'warn'),
  (3, 'error');
SQL
DELETE FROM logs
WHERE
  id = 2;

SELECT
  id,
  level
FROM
  logs
ORDER BY
  id;
idlevel
1info
3error
SQL Server PostgreSQL
Engine-specific syntax
Setup
CREATE TABLE logs (id INT, level VARCHAR(20));

INSERT INTO
  logs (id, level)
VALUES
  (1, 'info'),
  (2, 'warn'),
  (3, 'error');

DELETE FROM logs
WHERE
  id = 2;
SQL
SELECT
  id,
  level
FROM
  logs
ORDER BY
  id;
idlevel
1info
3error

This example emphasizes the remaining data rather than engine-specific delete status output.

Where this command helps.

  • removing obsolete or invalid records
  • cleaning up seed data after a temporary workflow

What the command is doing.

DELETE removes rows permanently unless the transaction is rolled back. Example content is usually clearest when it shows the rows that remain after the delete runs.