What is the DELETE Statement in SQL ?
Answer: The SQL DELETE statement is used to delete existing records from a table. We can use the WHERE clause with a DELETE query to delete the selected rows, otherwise all the records would be deleted.
Syntax
DELETE FROM table_name
WHERE condition;
You can combine N number of conditions using the AND or the OR operator.
Example
Suppose we have an Employees table:
| Employee_ID | Employee_Name | Salary |
|---|---|---|
| 101 | Anjali | 50000 |
| 102 | Priya | 45000 |
| 103 | Amit | 55000 |
If we want to delete Priya’s record:
DELETE FROM Employees
WHERE Employee_ID = 102;
After DELETE
| Employee_ID | Employee_Name | Salary |
|---|---|---|
| 101 | Anjali | 50000 |
| 103 | Amit | 55000 |
DELETE Example without WHERE CLAUSE (Delete All Records)
Important: If you use DELETE without a WHERE clause, all records in the table will be deleted, but the table structure will remain.
To delete all records from a table, use the DELETE statement without a WHERE clause.
DELETE FROM Employees;
After DELETE
| Employee_ID | Employee_Name | Salary |
|---|