sql server - Best way to design this database scenerio? -


Required archiving attachments for different entity types.

Say that we have a 3 unit type company, department and staff can have multiple attachments in each.

What is the best way to handle it?

Solution 1:

company table

  • CompanyId

section table

  • Type (Company, Department, Employee)
  • Employee
  • Employee < / Li>

    AttachmentType table

  • Attachment table

    • Attachment id
    • Typed (map for attachment type)
    • Entity ID (Company ID / Professionals: I can easily add new organization type in the future

      Cons: In this case Foreign key relationships created between the organizations can not be found in the attachment.

      Solution 2:

      Company table

      Company table

      • DeptId

      Employee table

      • Company ID (s)
    • Company ID
      • Attachment ID
      • Company ID (FK)
      <
    • Attachment id
    • Employee ID (FK)

    Professionals: Foreign Keys DATA

    Cons: I need a separate new attachment table to add a new unit.

    So what is the best way to go with thinking that I may have to add new institutions in the future? Please help and thank you in advance!


    Edit 1:

    Thank you for your reply friends.

    If I want to go with Solution 2, I see that the new column in the table of attachments makes it easy to map them instead of creating new attachment tables for each unit? Company table

    • Company ID

    Department table

    • DeptId

    Staff Table

    • Employee

    Attachment

    • Attachment ID
    • Employee ID (FK)
    • Department ID (FK)

    Am I missing something here?

  • I will definitely go with the solution # 2 for your solution to a # 1 solution really Not a supporter If you add a new unit, you want to add a new table for that unit and you can add or change existing code already to handle it. You should be able to create some generic objects that handle the pattern, so duplicate code is not a problem.


    Comments

    Popular posts from this blog

    Eclipse CDT variable colors in editor -

    AJAX doesn't send POST query -

    wpf - Custom Message Box Advice -