What is logical deletion and physical deletion?

off.tokyo
2 min readMay 17, 2021

What is logical deletion and physical deletion? | off.tokyo

What is logical deletion?

Logical deletion is the process of not actually deleting the data,

but setting a column called “flag” to make it appear as if the data has been deleted to the user.

For example, if you have a tweets table

For example, if you have a tweets table, you can add a boolean column called deleted_flag to the table.

In this state, the default value of the deleted_flag column is null.

In this way, when a user presses the delete button of a tweet,

the deleted_flag will be set to 1, and the tweet will be treated as deleted.

Physical Deletion

A physical deletion is an actual deletion in SQL,

and is also deleted from the database.

Therefore, you can’t restore or refer to the deleted data.

Advantages of Logical Deletion

As mentioned in the previous example,

it only acts as if the data has been deleted, so it is possible to restore the data immediately.

Another advantage of logical deletion is that it is faster than physical deletion.

Disadvantages of logical deletion

You don’t want to create NUll data in the database.

(I think this can be solved somehow, though.)

It is necessary to add a flag condition when

performing a narrowed search with a where clause.

--

--