Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Server XML columns substitute for Document DB?

Is it possible to use Sql Server XML columns as a substitute for a real Document DB (such as Couch or Mongo) ?

If I were to create a table with a guid PK Id and an XML column for the document. What would be the main problems compared to using a document DB?

Sql Server supports indexing over XML columns so querying should not be completely horrible?

like image 245
Roger Johansson Avatar asked Feb 25 '11 16:02

Roger Johansson


People also ask

How do I create an XML column in SQL Server?

Create columns and variablesDECLARE @x xml; Create a typed xml variable by specifying an XML schema collection, as shown in the following example. To pass an xml type parameter to a stored procedure, use a CREATE PROCEDURE statement, as shown in the following example.

Can we store XML in SQL?

In SQL Server, you usually store XML data in a column configured with the xml data type. The data type supports several methods that let you query and modify individual elements, attributes, and their values directly within the XML instance, rather than having to work with that instance as a whole.


3 Answers

You've got several questions in here:

Is it possible to use Sql Server XML columns as a substitute for a real Document DB (such as Couch or Mongo) ? Yes, you can use it as a substitute, but no, you probably wouldn't be satisfied with performance if you're exclusively storing XML and not leveraging any of SQL Server's relational tools.

If I were to create a table with a guid PK Id and an XML column for the document. What would be the main problems compared to using a document DB? In a nutshell, scaling out. SQL Server doesn't scale this kind of thing out well. You can do it with replication, but it's painful to manage relative to a "real" Document DB.

Sql Server supports indexing over XML columns so querying should not be completely horrible? The problem is that SQL Server's XML indexes can take several times the storage space of the original data. These indexes can't be maintained online (as in defrags), so you end up with locking issues during maintenance windows.

like image 158
Brent Ozar Avatar answered Sep 17 '22 23:09

Brent Ozar


I'm doing some experimenting with this on: http://rogeralsing.com/2011/03/02/linq-to-sqlxml-projections/

Query speed is 'decent' , it's nothing I'd use for scaling. But the joy of schema free storage running on standard infrastructure is quite nice.

like image 36
Roger Johansson Avatar answered Sep 17 '22 23:09

Roger Johansson


Yes, you can. Storing a document inside a SqlServer XML column will work and if you use standard XML serialization that will leave you with a decent ACID complant key/value store. Also, it will allow you to do queries on it with relative ease and you can join the results to data that you store in a more relational way. We do so, it works. If you store content in XML fields, storage demands are a lot lower than using NTEXT and querying it will be more flexible and faster.

What SqlServer will not get you (comparing to mongo) is the seamless failover of replica-sets an the autosharding of mongo. Also, atomic operations like incrementing a specific property deep inside a document is hard (though not impossible with the XQuery update function). Updates tend to be faster on most NoSql databases, because they are more relaxed on the "data is only safe on disk" principle.

like image 38
Teun D Avatar answered Sep 21 '22 23:09

Teun D