Computer Science · Ch 9 — Structured Query Language (SQL)
Data Deletion
Data Deletion
The Purpose of DELETE
The DELETE statement removes one or more entire records (rows) from a table. It does not remove the table structure itself — only the data inside it.
Syntax
DELETE FROM table_name WHERE condition;
The WHERE clause is what makes the deletion selective. Without it, every row in the table is removed.
Example from the Textbook
Suppose a student with RollNumber = 2 has left the school. The following MySQL command deletes that single record from the STUDENT table:
mysql> DELETE FROM STUDENT WHERE RollNumber = 2;
Query OK, 1 row affected (0.06 sec)
After deletion, a SELECT * query shows that the row for roll number 2 is gone. The remaining rows are:
| RollNumber | SName | SDateofBirth | GUID |
|---|---|---|---|
| 1 | Atharv Ahuja | 2003-05-15 | 444444444444 |
| 3 | Taleem Shah | 2002-02-28 | 101010101010 |
| 4 | John Dsouza | 2003-08-18 | 333333333333 |
| 5 | Ali Shah | 2003-07-05 | 101010101010 |
| 6 | Manika P. | 2002-03-10 | 466444444666 |
Five rows remain, confirming that only the targeted record was removed.
Critical Caution
Like the UPDATE statement, DELETE is dangerous without a WHERE clause. If you omit the condition, all records in the table are deleted — there is no warning or confirmation. Always double-check your WHERE condition before executing a DELETE command.
Key Points to Remember
DELETEremoves entire rows, not individual column values. …