Should I delete or disable a row in a relational database?

后端 未结 18 2340
忘了有多久
忘了有多久 2020-12-23 10:09

In a brand new program where space isn\'t really that big a deal, is it better to delete a row or to disable a row by let\'s say a boolean \"Disabled\" and have the program

18条回答
  •  遥遥无期
    2020-12-23 10:40

    It depends. (But you guessed that already, I'm sure.)

    In practice, the violation of proper usage here is almost always in the direction of deleting.

    The main bad consequence of deleting is how often there are dependent records in other tables whose referential integrity is lost when the parent record goes away.

    One red herring used to defend deletion (which you've already dealt with properly by dismissing the issue of storage capacity), is expecting that it will make any noticeable difference in query efficiency.

    There are too many cases where user or software issues cause someone to need to hit the big "Undo" button; if you delete, you're out of luck (at least without getting special help and aggravating people you'd rather be nice to.)

    The terminology I usually use is "Active" and "Inactive".


    A few more points to consider (by Totophil):

    1. Deleting a record in some databases will not automatically free up the disk space.
    2. Purging any sensitive information that you no longer require helps avoiding security risks.
    3. Data protection legislation might require your organisation under certain circumstances to purge any identifiable information about an individual. The legislation differs from country to country, some pointers:

      • EU http://ec.europa.eu/justice_home/fsj/privacy/law/index_en.htm
      • UK http://www.ico.gov.uk/what_we_cover/data_protection.aspx
      • Estonia http://www.riigiteataja.ee/ert/act.jsp?id=748829
    4. On the other hand you might be required by law to keep certain information.

提交回复
热议问题