sql - Map documents to different entities -


i have problem designing database.

i have table contains documents following table-structure:

[documents] id [int]  filename [varchar] fileformat [varchar] filecontent [image] 

in program: each document can standalone (without relationship entity) or relation object either of type customer or employee (some more coming soon)

each entity has id in database. example employee-table looks like:

[employee] id [int] fk_nameid [int] fk_addressid [int] fk_contactid [int] 

my idea create table connection of entity , document. thought like:

[documentconnection] documentid [int] entityid [int] entity [varchar] 

the entity-column in documentconnection-table contains table-name of relation.

in example of entity of type employee column contain "employee". in application build select-statement document reading entity-string database.

i'm not sure if way this.

i think better design have employeedocument table, customerdocument table, etc.

that allow use foreign keys entity tables, not possible in proposed design. in design, able put in entity , entityid columns , not enforceable via foreign key relationship relates existing entity.

the reason can see using documentconnection table if application needed dynamically create new types of relationships. assume isn't case since said each type of entity have own table.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -