【问题标题】:SQL Server XML schema: is there any way to add unique constraint on Xml?SQL Server XML 架构:有没有办法在 Xml 上添加唯一约束?
【发布时间】:2017-05-02 21:51:39
【问题描述】:

以下create xml schema collection代码返回的错误

消息 9336,第 16 层,状态 1,第 34 行 不支持 XML Schema 语法“唯一”。
create xml schema collection cs.T as N'  
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">  
  <xsd:element name="Column">
    <xsd:unique name="uniqueKey">
      <xsd:selector xpath="@ColumnKey"/>
      <xsd:field xpath="."/>
    </xsd:unique>
  </xsd:element>
</xsd:schema>';

有没有办法通过其他方式设置唯一性约束?

【问题讨论】:

    标签: sql-server xml xml-schema-collection


    【解决方案1】:

    没错:&lt;xsd:unique&gt; 不受支持。来自the documentation

    目前,SQL Server 不支持这些基于 XSD 的约束来强制唯一性或建立键和键引用。无法注册包含这些元素的 XML 模式。

    正如文档所述,同样的问题也适用于 &lt;xsd:key&gt;&lt;xsd:keyref&gt;

    【讨论】:

    • 有没有办法通过其他方式设置唯一性约束?
    猜你喜欢
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多