SQL Tutorial SQL Advanced SQL Database SQL References

SQL - DELETE Statement



The SQL DELETE statement 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 statement is given below:

DELETE FROM table_name
WHERE condition(s);

Example:

Consider a database containing a table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • 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:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800
    4KimAmsterdam303100
    6HuangBeijing282800
  • 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:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    3JoParis272800
    4KimAmsterdam303100
    6HuangBeijing282800

    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;