Database Structure involving dynamic fields

前端 未结 2 1757
一整个雨季
一整个雨季 2020-12-28 21:31

Im working on a project. Its mostly for learning purposes, i find actually trying a complicated project is the best way to learn a language after grasping the basics. Databa

相关标签:
2条回答
  • 2020-12-28 21:44

    I found this as was searching for something similar as the customer can submit custom fields for use later.

    i settled for using data type JSON which i appreciate was not available when this question was asked.

    0 讨论(0)
  • 2020-12-28 21:50

    You have reinvented an old antipattern called Entity-Attribute-Value. The idea of custom fields in a table is really logically incompatible with a relational database. A relation has a fixed number of fields.

    But even though it isn't properly relational, we still need to do it sometimes.

    There are a few methods to mimic custom fields in SQL, though most of them break rules of normalization. For some examples, see:

    • Product table, many kinds of product, each product has many parameters on StackOverflow
    • My presentation Extensible Data Modeling with MySQL
    • My book SQL Antipatterns: Avoiding the Pitfalls of Database Programming
    0 讨论(0)
提交回复
热议问题