Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Non-Deterministic Content Models

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

Before SQL Server 2005 Service Pack 1 (SP1), SQL Server rejected XML schemas that had non-deterministic content models. 

Beginning with SQL Server 2005 SP1, however, non-deterministic content models are accepted if the occurrence constraints are 0,1, or unbounded.

The following example attempts to create an XML schema with a non-deterministic content model. The code fails because it is not clear whether the <root> element should have a sequence of two <a> elements or if the <root> element should have two sequences, each with an <a> element.

CREATE XML SCHEMA COLLECTION MyCollection AS '
<schema xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="root">
        <complexType>
            <sequence minOccurs="1" maxOccurs="2">
                <element name="a" type="string" minOccurs="1" maxOccurs="2"/>
            </sequence>
        </complexType>
    </element>
</schema>
'
GO

The schema can be fixed by moving the occurrence constraint to a unique location. For example, the constraint can be moved to the containing sequence particle:

<sequence minOccurs="1" maxOccurs="4">
    <element name="a" type="string" minOccurs="1" maxOccurs="1"/>
</sequence>

Or the constraint can be moved to the contained element:

<sequence minOccurs="1" maxOccurs="1">
     <element name="a" type="string" minOccurs="1" maxOccurs="4"/>
</sequence>

The following schema would be rejected in versions of SQL Server before SQL Server 2005 SP1.

CREATE XML SCHEMA COLLECTION MyCollection AS '
<schema xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="root">
        <complexType>
            <sequence minOccurs="0" maxOccurs="unbounded">
                <element name="a" type="string" minOccurs="0" maxOccurs="1"/>
                <element name="b" type="string" minOccurs="1" maxOccurs="unbounded"/>
            </sequence>
        </complexType>
    </element>
</schema>
'
GO

Community Additions

ADD
Show:
© 2015 Microsoft