DELETE — Remove Rows
Remove rows from a table with DELETE FROM … WHERE, and understand why DELETE without WHERE empties the table.
Bumrah is released from the squad and his row must go. DELETE removes rows from a table — just the rows, the table itself stays.
Definition
DELETE is a DML statement that removes existing rows from a table. The WHERE clause decides which rows are removed; without WHERE, all rows are deleted, but the table and its structure remain (as an empty table).
- Removes rows — whole rows, not individual values (to blank one value,
UPDATEit to NULL). - WHERE — the filter; only rows that match are deleted.
- Table remains — unlike
DROP, the columns, data types and constraints stay.
Syntax
sql
DELETE FROM table_name
WHERE condition;| Part | Meaning |
|---|---|
DELETE FROM table_name | The table to delete rows from |
WHERE condition | Which row(s) should be deleted |
NOTE: Always use WHERE to avoid deleting all rows unintentionally.
Notice there is no column list — DELETE name FROM players is wrong. DELETE always removes complete rows.
Example — remove one row
sql
DELETE FROM players
WHERE id = 6;
SELECT * FROM players;After — Bumrah's row is gone:
| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
| 2 | Rohit Sharma | MI | India | 500 |
| 3 | Jos Buttler | RR | England | 850 |
| 4 | MS Dhoni | CSK | India | 350 |
| 5 | David Warner | DC | Australia | 700 |
Step by step: 1️⃣ WHERE finds id = 6 → 2️⃣ DELETE removes the row. The row is removed from the table for good.
Example — remove several rows with a condition
sql
DELETE FROM players
WHERE country = 'India'
AND runs < 500;| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
| 2 | Rohit Sharma | MI | India | 500 |
| 3 | Jos Buttler | RR | England | 850 |
| 5 | David Warner | DC | Australia | 700 |
Dhoni (350) and Bumrah (20) matched both conditions → (2 rows affected). Rohit has exactly 500, which is not < 500, so he stays.
DANGER — DELETE without WHERE
sql
DELETE FROM players;After — ALL rows deleted!
| id | name | team | country | runs |
|---|---|---|---|---|
| (empty — 0 rows) |
1️⃣ No WHERE = no filter → 2️⃣ EVERY row is deleted! The table still exists, but it is now completely EMPTY.
Deleting rows that other tables reference
If another table has a FOREIGN KEY pointing at a row (e.g. a contracts row pointing at team 'GT'), SQL Server blocks the delete of that parent row: "The DELETE statement conflicted with the REFERENCE constraint…". Delete the child rows first, or define the foreign key with ON DELETE CASCADE.
Common mistakes
- ❌
DELETE * FROM players WHERE id = 6(MS Access style). ✅DELETE FROM players WHERE id = 6— no*. - ❌
DELETE name FROM playersto blank a column. ✅UPDATE players SET name = NULL …(orALTER TABLE … DROP COLUMNto remove the column). - ❌ Forgetting WHERE → the table is emptied. ✅ Run the same WHERE with
SELECTfirst. - ❌
WHERE team = NULL→ 0 rows deleted. ✅WHERE team IS NULL. - ❌ Using
DROP TABLEto remove rows. ✅DROPdestroys the table;DELETEremoves rows.
SQL Server vs MySQL / PostgreSQL
DELETE FROM table WHERE … is identical everywhere. In SQL Server the word FROM is actually optional (DELETE players WHERE id = 6 works) — but always write it for clarity and portability.
Interview tip
Q: After DELETE FROM players (no WHERE), does the players table still exist?
A: Yes. DELETE removes rows only, so the table, its columns and constraints remain — it just has 0 rows. To remove the table itself you need DROP TABLE.
Key points to remember
- DELETE removes whole rows from a table; the table and its structure remain.
- Syntax: DELETE FROM table WHERE condition; — no column list and no *.
- WHERE decides which rows go; without WHERE, every row is deleted and the table is left empty.
- To blank a single value use UPDATE … SET col = NULL, not DELETE.
- A parent row referenced by a FOREIGN KEY can't be deleted until its child rows are removed (unless ON DELETE CASCADE).
- Test the WHERE with a SELECT before running the DELETE.
Try it yourself
Remove one row: Bumrah (id 6)
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Remove rows matching two conditions
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
DANGER: DELETE without WHERE
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Practice: delete one innings
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Revision Flashcards
Tap a card to flip it and see the answer.
