SQL Delete

The DELETE statement removes records from a table. Always use WHERE carefully to avoid deleting all rows.

On this page

SQL DELETE Statement

The DELETE statement is used to remove records from a table.

Basic Syntax

DELETE FROM table_name
WHERE condition;

Delete a Specific Record

Delete a customer with a specific id:

DELETE FROM customers
WHERE id = 5;

Delete Multiple Records

Delete all inactive customers:

DELETE FROM customers
WHERE status = 'inactive';

IMPORTANT: DELETE Without WHERE

If you omit the WHERE clause, ALL rows in the table will be deleted.

-- WARNING: Deletes every row
DELETE FROM customers;

The table structure remains, but all data is removed.

Test Before Delete

Always test your condition with SELECT before running DELETE:

-- Step 1: Test
SELECT id, status
FROM customers
WHERE status = 'inactive';

-- Step 2: Delete
DELETE FROM customers
WHERE status = 'inactive';

DELETE vs TRUNCATE

TRUNCATE removes all rows from a table more quickly than DELETE, but it cannot use a WHERE clause.

TRUNCATE TABLE customers;
  • DELETE can remove selected rows
  • TRUNCATE removes all rows
  • TRUNCATE may reset AUTO_INCREMENT counters (database-specific)

Foreign Key Considerations

If a table is referenced by foreign keys, deleting rows may fail or cascade depending on the constraint definition.

Safe Delete Practices

  • Always use WHERE unless intentionally clearing the table
  • Test with SELECT first
  • Use transactions when deleting critical data

Next Step

Continue with SQL SELECT TOP (or LIMIT) to learn how to restrict the number of returned rows.