Database Structure involving dynamic fields

前端 未结 2 1818
一整个雨季
一整个雨季 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: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

提交回复
热议问题