0

I worked in big project last year, it was Educational Management System! My team solved a lot of problems during developing. But we had one problem and now I am again got it.

Problem is:

how to design database structure, if some records that have references can be deleted from Software Interface?

Simple Example: Assume that, you have tables :

Students, StudentClass, Marks, Classes

. So, if I try to delete record from 'Classes' table, it will be impossible, because 'StudentClass' table has reference to 'Classes' table. Of course, it is possible delete records from depending tables(StudentClass, etc.) and then delete 'Classes' record, but i need to keep data.

I found solution, in all tables that is referenced by other, i create column 'IsDeleted'. It means that If i want to delete record from 'Classes' table, i just update 'IsDeleted' column to 1. To show to users, i use "SELECT * .... FROM ... WHERE Classes.IsDeleted = 0".

This my solution! Can you tell me, how you solve such problems, share with me your approaches, pls! Any opinions will be interesting for me! Thanks in advance for your reply!!!!

EDIT:

Any solutions else?

4

1 回答 1

0

非常经典的问题,我已经看到您的解决方案实施了很多次。通常它被称为“软”删除,因为数据库中仍有数据,但它不会出现在 UI 中。

我想到了两个潜在的缺点:

  1. 开发人员在某些时候总是忘记按已删除标志进行过滤。
  2. 如果您从不删除,表可能会变大,并且在某些时候这会影响查询时间。

缓解这两个问题的一种潜在解决方案是不时运行一项作业,将已删除的数据存档/移动到其他地方。如果需要,您可以随时查询或稍后恢复它,但它不会影响其他“实时”记录。

于 2013-04-08T18:08:29.503 回答