MySQL: Embedded JSON vs table

后端 未结 1 1164
南笙
南笙 2021-01-11 16:10

I\'m designing the database schema for a video production project management app and struggling with how to persist some embedded, but not repeatable data. In the few CS cou

相关标签:
1条回答
  • 2021-01-11 16:28

    ONE of the reasons of normalizing a database is to reduce redundancy (your "repeatable blocks")

    ANOTHER reason is to allow "backwards" querying. If you wanted to know which video was shot at "15 Pike Place", your JSON solution will fail (you'll have to resort to sequential reading, decoding JSON which defeats the purpose of a RDBMS)

    Good rules of thumb:

    • Structured data - put in tables and columns
    • Data that might be part of query conditions - put in tables and columns
    • Unstructured data you know you'll never query by - put into BLOBs, XML or JSON fields

    If in doubt, use tables and columns. You might have to spend some extra time initially, but you will never regret it. People have regretted their choice for JSON fields (or XML, for that matter) again and again and again. Did I mention "again"?

    0 讨论(0)
提交回复
热议问题