DELETE command in SQL
The DELETE statement in SQL is used to remove rows from a table. It's important to use the DELETE statement carefully, especially when not specifying a WHERE clause, as it can remove all rows from the table.
SQL Syntax
WHERE condition;
The syntax has the following parameters:
- table_name: The name of the table from which we want to delete rows.
- condition: The condition that specifies which rows to delete. If we omit the WHERE clause, all rows in the table will be deleted.
Example: Delete Specific Rows Use the WHERE clause to specify which rows to delete. Suppose we have a table named employees and we want to delete an employee with a specific employee_id.
SQL
WHERE employee_id = 10;
This statement deletes the row from the employees table where the employee_id is 10.
Example: Delete All Rows To delete all rows from a table, we can omit the WHERE clause. Be cautious with this operation as it removes all data from the table.
SQL
This statement deletes all rows from the employees table, but the table itself is not deleted.