-2

I am creating a website where the user has the possibility to upload content (pictures, videos pdf's etc.).

Each type of content has a different number of properties with corresponding values.

I have thought about making this design:

enter image description here

Is this the right way to do it?

Since each type of property has a predetermined set of property-names, should I make a relation between the two? Or would it be fine to handle this in code instead?

philipxy
  • 14,867
  • 6
  • 39
  • 83
Glacierdk
  • 31
  • 1
  • 7
  • 2
    It is useless to ask advise about data base schema. To make a good schema developer should know all smallest bussiness details. For example It seems to me that you don't need at least 2 tables or maybe 3 but I don' t know anything about the real situation. – Serge Jan 17 '22 at 00:16
  • Does this answer your question? [What are the options for storing hierarchical data in a relational database?](https://stackoverflow.com/questions/4048151/what-are-the-options-for-storing-hierarchical-data-in-a-relational-database) – philipxy Jan 17 '22 at 00:39
  • Please before considering posting read the manual/reference & google any error message & many clear, concise & precise phrasings of your question/problem/goal, with & without your particular names/strings/numbers, 'site:stackoverflow.com' & tags; read many answers. Reflect research. Please [use text, not images/links, for text--including tables & ERDs](https://meta.stackoverflow.com/q/285551/3404097). Give just what you need & relate it to your problem. Use images only for what cannot be expressed as text or to augment text. Include a legend/key & explanation. [ask] [Help] – philipxy Jan 17 '22 at 07:48

1 Answers1

1

Normally in a relational database you should use columns to model the attributes of an entity. So "Plan A" is to create PictureContent, PDFContent, etc tables in the database.

The design you are proposing is called Entity-Attribute-Value or EAV. It has some pretty serious drawbacks, but it is occasionally useful, typically when data sizes are moderate and you need change your metadata at runtime.

If you do need a dynamic schema, consider using JSON instead of EAV, which can easilly be serialized into .NET objects, or accessed dynamically.

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67