SQL DELETE Keyword
The SQL DELETE keyword is used to delete the existing records from a table. The SQL WHERE clause can be used with the DELETE statement to delete the selected rows, otherwise all records will be deleted.
Syntax
The syntax for using DELETE keyword is given below:
DELETE table_name WHERE condition(s);
Example:
Consider a database containing a table called Employee with the following records:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
-
To delete the records of an employee whose EmpID is 5, the SQL query is:
DELETE FROM Employee WHERE EmpID = 5; --See the result SELECT * FROM Employee
Now the Employee table will contain following records:
EmpID Name City Age Salary 1 John London 25 3000 2 Marry New York 24 2750 3 Jo Paris 27 2800 4 Kim Amsterdam 30 3100 6 Huang Beijing 28 2800 -
Similarly, to delete the records of an employee where city starts with 'New', the SQL query is:
DELETE FROM Employee WHERE City LIKE 'New%'; -- see the result SELECT * from Employee;
Now the Employee table will contain following records:
EmpID Name City Age Salary 1 John London 25 3000 3 Jo Paris 27 2800 4 Kim Amsterdam 30 3100 6 Huang Beijing 28 2800
In MS Access, the same can be achieved using below query:
/* MS Access SQL code */ DELETE FROM Employee WHERE City LIKE 'New*'; -- see the result SELECT * from Employee;
❮ SQL Keywords