We will use the DELETE
DML statement for deletion of data. The DELETE
statement at a minimum expects the name of the table. Similar to the UPDATE
statement, it is recommended that the DELETE
statement is always used with filter criteria to avoid loss of data.
The DELETE
statement should be used when a record has to be permanently removed from the table.
Note
To avoid permanent loss or deletion of data Boolean flags are used to determine if a record is active or inactive (1 or 0). These are called soft deletes and help us retain data in the long run.
In the preceding example, we are deleting the records from the students table that match the criterion of student_id
equal to 4
. As there is only one record that matches that criterion, that record has been deleted. The recommendations that were made above about how to use the filter criterion apply for the DELETE
statement too.