SQL DELETE
SQL

SQL DELETE — How to Remove Rows from a Table

CHAPTER 11 of 30 SQL Tutorial — Free Course on Neotech Navigators
The SQL DELETE statement removes one or more rows from a table. Unlike UPDATE (which changes values), DELETE removes entire rows permanently. In this chapter, you will learn how to delete specific rows, delete all rows, and why the WHERE clause is absolutely critical with DELETE.

The SQL DELETE Statement

The DELETE statement removes rows from a table based on a condition:

SQL — DELETE Syntax
DELETE FROM table_name
WHERE condition;

We will use this Employees table:

TABLE: Employees
+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 1  | Priya K.  | Sales      | 55000  | Mumbai    |
| 2  | John D.   | Marketing  | 62000  | London    |
| 3  | Arun M.   | IT         | 78000  | Delhi     |
| 4  | Emma W.   | Sales      | 51000  | Sydney    |
| 5  | Ravi S.   | IT         | 72000  | Mumbai    |
| 6  | Sara L.   | HR         | 58000  | New York  |
+----+-----------+------------+--------+-----------+

Delete a Specific Row

Use a WHERE clause that uniquely identifies the row, typically by primary key:

SQL
DELETE FROM Employees
WHERE ID = 4;
✓ RESULT — Emma W. Removed
+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 1  | Priya K.  | Sales      | 55000  | Mumbai    |
| 2  | John D.   | Marketing  | 62000  | London    |
| 3  | Arun M.   | IT         | 78000  | Delhi     |
| 5  | Ravi S.   | IT         | 72000  | Mumbai    |
| 6  | Sara L.   | HR         | 58000  | New York  |
+----+-----------+------------+--------+-----------+
5 rows remaining (Emma W. deleted)

Delete Multiple Rows

When the WHERE clause matches multiple rows, all matching rows are deleted. You can use AND, OR operators to combine conditions:

SQL — Delete All Sales Employees
DELETE FROM Employees
WHERE Department = 'Sales';
✓ 2 Rows Deleted
Priya K. and Emma W. are removed.
4 rows remaining.

Delete employees earning below 55,000:

SQL
DELETE FROM Employees
WHERE Salary < 55000;

DELETE Without WHERE — Deletes Everything

⚠️ Critical Warning

Running DELETE without a WHERE clause removes every row from the table. The table structure remains, but all data is gone. This is almost always a catastrophic mistake.

SQL — DANGEROUS
-- ⚠️ This deletes ALL employees!
DELETE FROM Employees;

After this, the Employees table exists but contains zero rows. All data is permanently lost unless you have a backup.

DELETE vs TRUNCATE vs DROP

Command What It Does WHERE Clause? Can Undo?
DELETE Removes specific rows Yes Yes (with transaction)
TRUNCATE Removes ALL rows (faster) No No in most databases
DROP TABLE Removes the entire table No No

Best Practices for DELETE

Practice Why
Always use WHERE Prevents deleting all rows accidentally
Test with SELECT first Preview which rows will be deleted
Use primary key Guarantees you delete exactly one row
Back up before bulk deletes Deleted data cannot be recovered without backup

💡 Pro Tip: Test Before You Delete

Replace DELETE FROM with SELECT * FROM using the same WHERE clause. Verify the correct rows are shown, then switch back to DELETE.

SQL — Test First
-- Step 1: Preview
SELECT * FROM Employees
WHERE City = 'Sydney';

-- Step 2: Delete if correct
DELETE FROM Employees
WHERE City = 'Sydney';

For a complete reference of the DELETE syntax, see the official MySQL DELETE documentation. In the next chapter, you will learn how to limit the number of rows returned with SQL TOP, LIMIT, and FETCH FIRST.

If you work with data regularly, explore our ready-made Dashboard Templates on NextGenTemplates that use SQL-powered data for business reporting.

📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.

🧪 Try It Yourself

Write a DELETE statement that removes all employees from Mumbai. Then write a SELECT to verify they are gone.

ANSWER
DELETE FROM Employees
WHERE City = 'Mumbai';

-- Verify
SELECT * FROM Employees;

Expected Output (after delete):

+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 2  | John D.   | Marketing  | 62000  | London    |
| 3  | Arun M.   | IT         | 78000  | Delhi     |
| 4  | Emma W.   | Sales      | 51000  | Sydney    |
| 6  | Sara L.   | HR         | 58000  | New York  |
+----+-----------+------------+--------+-----------+

📝 What You Learned in This Chapter

  • DELETE FROM removes rows from a table
  • Always use a WHERE clause to target specific rows
  • DELETE without WHERE removes ALL rows from the table
  • Test with SELECT first to preview which rows will be deleted
  • DELETE removes rows but keeps the table structure intact
  • TRUNCATE removes all rows faster; DROP removes the entire table

Frequently Asked Questions

What is the difference between DELETE and TRUNCATE?
DELETE removes specific rows using a WHERE clause and can be rolled back inside a transaction. TRUNCATE removes all rows at once, is faster on large tables, resets auto-increment counters, and cannot be rolled back in most databases.
Can I undo a DELETE in SQL?
Only if the DELETE was inside a transaction that has not been committed. Use ROLLBACK to undo. If auto-commit is on (the default), the delete is permanent immediately. Always test with SELECT first and back up important data.
Does DELETE remove the table structure?
No. DELETE only removes rows (data). The table, its columns, indexes, and constraints all remain. To remove the entire table including its structure, use DROP TABLE.
What happens to auto-increment after DELETE?
After DELETE, the auto-increment counter is not reset. If you delete ID 6 and insert a new row, the new ID will be 7, not 6. TRUNCATE resets the counter back to 1 in most databases.
Can I delete rows from multiple tables at once?
Standard SQL does not support deleting from multiple tables in one statement. You need separate DELETE statements for each table. Some databases like MySQL support multi-table DELETE syntax, but it is not standard and should be used carefully.

📖 Chapter 11 of 30 — SQL Tutorial on Neotech Navigators

PK
Meet PK, the founder of NeotechNavigators.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your data analysis skills to the next level!
https://neotechnavigators.com