Best way to design this database scenario?

前端 未结 5 380
你的背包
你的背包 2020-12-17 00:46

Requirement is to store attachments for different entity types.

Say we have 3 entity types Company , Department and Employee. Each can have multiple attachments (doc

相关标签:
5条回答
  • 2020-12-17 00:57

    I would go with option 2.

    Something like this:

    alt text http://img84.imageshack.us/img84/815/dbso.png

    0 讨论(0)
  • 2020-12-17 01:00

    Other things to consider:

    Are you going to need to roll up attachments? i.e. an employee's attachments are associated with his/her department and their company? if this is a frequent query a single attachment table and a separate and heavily index entity look-up table option may give better query performance.

    Also, Are the attachments going to be many and/or huge enough that you need to put those table(s) on a separate device, or another storage system (i.e. file system pointers)? Management is an issue as well as performance.

    0 讨论(0)
  • 2020-12-17 01:04

    Hope this is self-explanatory.

    0 讨论(0)
  • 2020-12-17 01:07

    I'd definitely go with solution #2. Your one pro for solution #1 isn't really a pro. If you add a new entity you're going to necessarily have to already add a new table for that entity and you'll already be adding or changing existing code to handle it. You should be able to make some generic objects that handle the pattern so that duplicated code isn't a problem.

    0 讨论(0)
  • 2020-12-17 01:09

    I vote for solution 2 because this way you can enforce referential integrity in a proper way. In addition you can easily (if needed) add fields for special attachments (for instance EmployeeAttachments might have a bit field "PersonalPicture" or similar)

    0 讨论(0)
提交回复
热议问题