SQL Delete Statement

DELETE command is used to remove existing records from the table.

Syntax:-


DELETE FROM table_name
WHERE [CONDITION];

Example:-
Suppose you have two records in the employees table which has two records.

 SELECT * FROM employees

Output:-


+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email          | address    |
+----+------------+-----------+----------------+------------+
|  1 | Virat      | Kohli     | virat@abc.com  | Delhi      |
|  2 | rohit      | Sharma    | rohit@abc.com  | Mumbai     |
+----+------------+-----------+----------------+------------+

Apply WHERE Condition

FIRST CASE:- Now, You want to delete the record which has id=1;


DELETE FROM employees WHERE id=1

Now, check the record of the table.


+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email          | address    |
+----+------------+-----------+----------------+------------+
|  2 | rohit      | Sharma    | rohit@abc.com  | Mumbai     |
+----+------------+-----------+----------------+------------+

Without WHERE Condition

SECOND CASE:- If you do not use where condition then all records will be deleted.

DELETE FROM employees

Now check the results of the employees table

 SELECT * FROM employees

Output:- employees table would not have any record.

Note:- If you do not use WHERE condition on DELETE Statement then all records will be deleted from the table, so please delete the record carefully.