The SQL DELETE statement is used to remove one or more rows from a table. Its basic syntax is as follows:
DELETE FROM table_name
WHERE condition;
table_name
: Name of the table from which you want to delete rows.condition
: Optional. It specifies which rows to delete based on a certain condition. If omitted, all rows in the table will be deleted.For example, if you have a table called customers
and you want to delete a customer with a specific customer_id
, you can execute
DELETE FROM customers
WHERE customer_id = 123;
This will delete the row(s) from the customers
table where the customer_id
is 123.
If you omit the WHERE
clause, like so:
DELETE FROM customers;
This will delete all rows from the customers
table, effectively emptying it. However, be cautious when using DELETE
without a WHERE
clause, as it will remove all records from the table, which may not be what you intended. Always ensure you have a backup or are certain of the consequences before executing such a statement.