The SQL DELETE statement is used to delete existing records in a table.

DELETE FROM table_name WHERE condition;

Parameters:

  • DELETE FROM table_name  – The name of the table where records will be deleted.
  • WHERE condition – Specifies which records should be deleted. If you omit it, all records in the table will be deleted.

Example:

Consider the Products table containing the following records:

id product quantity price
1 Glass Table 10 899.99
2 Oak Chair 28 530.50
3 Gloss Coffee Table 34 240.10
4 Oak Table 10 450.90
5 Birch Chair 8 60.80
DELETE FROM Products WHERE ‘product’ LIKE ‘%Chair’;

This statement will delete all products which contain the word ‘Chair’ in ‘product’ column. It will produce the following table:

id product quantity price
1 Glass Table 10 899.99
3 Gloss Coffee Table 34 240.10
4 Oak Table 10 450.90

If you want to delete all the records in a table you can simply use:

DELETE FROM Products;

Notes:

  • The user must have data manipulation privileges on the table or column (DELETE privilege). You need only the SELECT privilege for any columns that are only read, such as those named in the WHERE clause.
  • SQL requires single quotes around text values. However, numeric fields should not be enclosed in quotes.

Was this article helpful?