i am going to be storing some text in a database. The text happens to be xml.
i’m only storing and reading the “blob” of text (i am not using any of the xml querying or indexing facilities).
Is there any advantage to declaring the column as xml:
CREATE TABLE docs (pk INT PRIMARY KEY, xCol XML not null)
rather than nvarchar(max):
CREATE TABLE docs (pk INT PRIMARY KEY, xCol NVARCHAR(max) not null)
i figure that if i give SQL Server the hint that the text is actually xml, then it can apply compression for more efficient storage.
Note: The third option is for me to compress the text client-side and store the data in a varbinary(max) blob column.
Storing this as XML will most likely result in smaller storage size than nvarchar (I have found this to be true, at least due to removing irrelevant white space and other such formatting). However, SQL server will check that the XML is well-formed before each insert and update, so you can potentially suffer a performance penalty at those times. I would argue that this check is also an advantage like any data-type check.