Sql-server – What’s the relationship between Documents, XSDs and Collections

sql serverxmlxsd

I have a number of XML Schema Definitions describing business objects. It's unclear to me what the correct way to deploy these is if my intention is to make typed xml columns. The name Xml Schema Collection implies that more than one Xsd Document definition can exist in a collection, but any example I look at shows a Collection as the specific constraint on the column, not a document within it.

Do I create a schema collection called 'BusinessObjects' and create individual Xsd Documents inside it? Do I make one Collection for each Document?

Best Answer

Yes, you are allowed to create multiple schema namespaces within a collection (in the Examples section of CREATE XML SCHEMA COLLECTION, see B. Specifying multiple schema namespaces in a schema collection).

But you can only associate a single XML Schema Collection with an XML field or variable. So whatever schema definitions you might put into a collection should all be relevant to the XML documents that you are going to store in the XML field or variable that will be assigned that XML SCHEMA COLLECTION.

If you will have different XML fields for different types of entities, then I would think those should have their own XML SCHEMA COLLECTIONs.

For more information, please see: