In a Database Management System (DBMS), there are situations where certain records in a table are no longer required. For example, a student may leave an institution, or outdated information may need to be removed from a database.
The DELETE statement is used to remove one or more records from a table. This command allows users to delete specific rows based on a given condition.
The DELETE query is a Data Manipulation Language (DML) command used to remove existing records (rows) from a table in a database.
DELETE FROM table_name
WHERE condition;
Where:
When the DELETE command is executed:
Suppose we have a table named students.
| id | name | age | course |
|---|---|---|---|
| 1 | Rahul | 20 | BCA |
| 2 | Anita | 21 | BBA |
| 3 | Rohit | 19 | BCA |
| 4 | Priya | 22 | BCom |
DELETE FROM students
WHERE id = 3;
| id | name | age | course |
|---|---|---|---|
| 1 | Rahul | 20 | BCA |
| 2 | Anita | 21 | BBA |
| 4 | Priya | 22 | BCom |
The record where id = 3 has been removed.
DELETE FROM students
WHERE course = 'BCA';
This query deletes all students enrolled in the BCA course.
If the WHERE clause is omitted, all records from the table will be deleted.
DELETE FROM students;
This removes all rows from the table but the table structure remains unchanged.
DELETE command removes specific records from a table.DELETE is a DML command.WHERE, all rows will be removed.The DELETE command is used to remove unwanted records from a table in a database. It allows users to delete specific rows using conditions or remove all records from a table if necessary. Proper use of the WHERE clause ensures that only the intended data is deleted.