DB-en

What is logical deletion and physical deletion?

0
0

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.

 

related

 

Pocket
LinkedIn にシェア

りょすけ
毎月3万人以上のプログラマーが訪れるoff.tokyoで、プログラマーさん向けのアンケートを実施しています、アンケートに無料回答すると、他の人の投票も見ることが出来ます!

学びたいプログラミング言語は何ですか?

 vaaaval@gmail.com



  • この記事を書いた人
  • 最新記事

藤沢瞭介(Ryosuke Hujisawa)

りょすけと申します。18歳からプログラミングをはじめ、今はフロントエンドでReactを書いたり、AIの勉強を頑張っています。off.tokyoでは、ハイテクやガジェット、それからプログラミングに関する情報まで、エンジニアに役立つ情報を日々発信しています!

-DB-en

Copyright© off.tokyo , 2021 All Rights Reserved Powered by AFFINGER5.