When to use the XML Datatype

When I first heard of the XML Datatype, I had mixed feelings. The reason is because from a traditional approach, all data structures can be represented using the classical entity relationship model. For me, a problem arises when trying to represent “documents”. When I say documents, I don’t just mean things like “Word Docs”. What I mean by that is data structures that mean nothing when the data is broken up into segments, however when represented in a whole document, that’s where the only relevance comes in.

An example of this is a contract. It is possible to take disparate pieces of a contract and break it into separate rows and columns according to the contract terms. However, when you break a contract up into individual pieces, it means nothing when it’s separate. It’s context is only meaningful when the pieces of the contract are together. This is an example of when to use the XML Datatype.

I recently wrote a rules engine, where I created all the rules using XML. When I showed some people, their immediate reaction was, “why can’t we break these individual parts of the rule into a table”. My answer was, “because separated, these individual rule items mean nothing, there is no reason to separate them. They only mean something when they are put together because that defines the rule”. In other words, the entire rule is atomic, there is no reason whatsoever to break it apart. When it is separate it has no meaning.

More and more I am seeing instances where this has relevance. Ask yourself, does it make sense to break this data up? Will it ever have relevance when it is separated? If not, then the XML Datatype may be appropriate for you.

4 comments
Srini 12 Apr 2012 at 1:03 am

Good means of explaining it.

DBATAG 09 Jul 2011 at 12:21 am

During my training sessions, even a lot of participants have the same feeling as you had. But you described this in a beautiful way, specially the Contract example, I am going to quote this example in my future training sessions.

Thanks
DBATAG
Email : [email protected]
http://sqlServer-Training.com/
http://dbatag.com/

Featured Articles

 Site Author

  • Thanks for visiting!
css.php