Is it “bad” to store XML in a database?

后端 未结 7 1534
感动是毒
感动是毒 2021-02-02 11:06

I have heard from several sources that storing XML in a database is \"bad\", but I have never seen/heard an actual explanation of why that is. Is it true? If it is true, can y

7条回答
  •  不要未来只要你来
    2021-02-02 12:00

    Storing XML, JSON, YAML, comma-seperated lists, binary blobs, or anything else in a database is not bad ... per se.

    It can indicate a lack of understanding of what a database is for (storing data that is related to other data) and conjures up visions of databases with single column tables called data1, data2, etc. ... with each table row holding a +5 MB entry of XML encoded relational data.

    On the other hand, there are many valid cases that can be made for such a structure -- rapidly changing configurations might be represented in JSON and stored in a two column table structured like this:

    dbo.good_table
    ApplicationID (bigint)
    Configuration (varchar(max))
    

    The difference between the above table and a table like this:

    dbo.bad_table
    ApplicationID (bigint)
    ApplicationMembers(xml)
    

    Is that good_table is enabling rapid access to a piece of data (the configuration), while the bad_table is using the database as an ofttimes expensive (and slow) hard disk.

提交回复
热议问题