Day 67 – SQL DELETE Keyword
SQL DELETE keyword is used to delete one or more rows from a table. The DELETE statement can be used to remove either all rows or a subset of rows based on certain criteria.
The basic syntax for using the DELETE keyword is as follows:
DELETE FROM table_name
WHERE condition;
Here, table_name
is the name of the table from which rows will be deleted, and condition
is the expression that specifies which rows to delete. If the WHERE
clause is omitted, then all rows in the table will be deleted.
For example, to delete all rows from a table named “Customers”, the SQL statement would be:
DELETE FROM Customers;
This would delete all rows from the “Customers” table.
Alternatively, to delete only the rows from the “Customers” table where the “City” column is set to “Paris”, the SQL statement would be:
DELETE FROM Customers
WHERE City = 'Paris';
This would delete only the rows from the “Customers” table where the “City” column is set to “Paris”.
It’s important to note that the DELETE statement permanently removes the specified rows from the table, and this operation cannot be undone. Therefore, it’s recommended to use the DELETE statement with caution and to always make a backup of the table or the database before executing a DELETE statement.