When can I save JSON or XML data in an SQL Table

前端 未结 8 1725
星月不相逢
星月不相逢 2020-11-27 12:04

When using SQL or MySQL (or any relational DB for that matter) - I understand that saving the data in regular columns is better for indexing sake a

8条回答
  •  臣服心动
    2020-11-27 12:30

    The question you have to ask is:

    Am I tied to using only this database?

    DO

    1. If you can use a different database to store JSON, use a document storage solution such as CouchDB, DynamoDB or MongoDB.
    2. Use these document storage DB's ability to index and search hierarchical data.
    3. Use a relational database for your relational data.
    4. Use a relational database for reporting, data warehousing and data mining.

    DON'T

    1. Store JSON as string if possible.
    2. Try and come up with max length of JSON data.
    3. Use varchar to store JSON (use text/blob if you must).
    4. Try and search through stored JSON for values.
    5. Worry about escaping JSON to store as string.

提交回复
热议问题