Understanding SQL DELETE Statement with Examples
The SQL DELETE statement removes existing records from a table based on specified conditions. It is essential for keeping your data clean and relevant. This guide focuses on practical, real-world examples of using DELETE safely.
Complete Python Course with Advance topics:-
SQL Tutorial:-
Example Scenario: Student Table
| ID | STUDENT_NAME | ADDRESS |
|---|---|---|
| 101 | Vikram Singh | Varanasi |
| 102 | Anita Sharma | Mumbai |
| 103 | Sumit Yadav | Jaipur |
Deleting a Single Record
DELETE FROM student_info WHERE id = 103;
After execution, the student with ID 103 is removed and only IDs 101 and 102 remain.
Deleting with Multiple Conditions
You can combine conditions with AND / OR for precise deletions.
DELETE FROM student_info
WHERE address = 'Jaipur' AND id > 100;
Deleting a Limited Number of Rows
In MySQL you can limit how many rows a DELETE affects using LIMIT ÔÇö useful for batch cleanups.
DELETE FROM student_info
WHERE address = 'Mumbai'
ORDER BY id
LIMIT 1;
Using Transactions to Undo a DELETE
Because DELETE is irreversible once committed, wrap risky deletes in a transaction so you can roll back mistakes.
START TRANSACTION;
DELETE FROM student_info WHERE id = 102;
-- check results, then:
ROLLBACK; -- undo
-- or
COMMIT; -- make permanent
Important Notes
- Condition is Crucial: Without WHERE, DELETE removes all rows.
- Backup Before Deleting: Deletion is irreversible without a backup.
- Verify First: Run
SELECT *with the same WHERE before deleting.
Download New Real Time Projects:- Click here
Complete Advance AI topics:-
Conclusion
The DELETE statement is a powerful tool for maintaining database integrity. By adding conditions, limiting rows, and using transactions, you keep your database accurate and safe. For more database tips and tutorials, stay connected with .
delete all data from table sql
sql delete statement w3schools
delete row in sql
sql delete with limit
sql delete multiple conditions
delete with transaction sql
delete table query in sql
delete query in mysql