Loading
SQL DELETE
The DELETE command in SQL is used to remove existing records (rows) from a database table.

Whenever data is no longer required such as removing inactive users, outdated records, or incorrect entries the DELETE command is used.

Important: The DELETE command permanently removes data from table.


Understanding DELETE

A database table can be compared to a register or spreadsheet.

  • INSERT - adds new rows
  • UPDATE - modifies existing rows
  • DELETE - removes rows completely
Using DELETE is similar to crossing out an entire row from a register.


Example: Students Table

idnamemarks
1Rahul92
2Anjali90
3Amit88


Why Use the DELETE Command?

The DELETE command is used to

  • Remove unnecessary or outdated records
  • Delete incorrect data
  • Maintain clean and accurate tables
  • Remove records based on specific conditions


Syntax

DELETE FROM table_name
WHERE condition;

  • DELETE FROM specifies the table
  • WHERE specifies which rows should be removed


Deleting a Specific Record

DELETE FROM students
WHERE id = 3;


Result

Only the record with id = 3 is removed.

idnamemarks
1Rahul92
2Anjali90


Deleting Multiple Records Using a Condition

DELETE FROM students
WHERE marks < 90;

This removes all students whose marks are less than 90.


Deleting All Records from a Table

DELETE FROM students;

This deletes all rows from the table but keeps the table structure intact.


Difference Between DELETE and TRUNCATE

DELETETRUNCATE
Deletes selected rowsDeletes all rows
Supports WHERE clauseDoes not support WHERE
Can be rolled back (in transactions)Cannot be rolled back
Slower than TRUNCATEFaster


Important Rules for Best Practices

  • Always use WHERE unless you intend to delete all records
  • Verify data using SELECT before deleting
  • DELETE operations are permanent
  • Use transactions if rollback support is required


Two Minute Dril

  • DELETE removes rows from a table
  • DELETE FROM specifies the table
  • WHERE controls which records are deleted
  • Without WHERE, all rows are removed 
  • DELETE keeps the table structure intact
  • DELETE operations are permanent