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.

SQL Delete Statement – Interview Questions

Q 1: What does DELETE do?
Ans: It removes specific rows from a table.
Q 2: DELETE syntax?
Ans: DELETE FROM table WHERE condition;
Q 3: Can DELETE remove all rows?
Ans: Yes, if WHERE clause is omitted.
Q 4: Is DELETE recoverable?
Ans: Only if transactions or backups exist.
Q 5: Does DELETE remove table structure?
Ans: No, only data is removed.

SQL Delete Statement – Objective Questions (MCQs)

Q1. Which SQL command removes records from a table?






Q2. Which clause is used to delete specific rows?






Q3. What happens if WHERE clause is omitted in DELETE?






Q4. DELETE statement belongs to which SQL category?






Q5. Which command deletes table data but keeps structure?






Related SQL Delete Statement Topics