如何在XML架构中使用datetime2类型?



>我正在尝试在集合和表中使用SQL Server XML SCHEMA类型,如datetime2

CREATE XML SCHEMA COLLECTION [XmlValuesSchemaCollection_datetime2] AS 
'<?xml version="1.0"?>
<xsd:schema 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sql2008/SqlTypes.xsd"
attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:element name="datetime2" type="xsd:datetime2"/>
</xsd:schema>';
GO
CREATE TABLE XmlValuesTable_datetime2 (
[uid] [int] IDENTITY PRIMARY KEY,
v XML(XmlValuesSchemaCollection_datetime2) NOT NULL
);
GO
INSERT INTO XmlValuesTable_datetime2 (v)  
VALUES (N'<datetime2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">2014-06-18 06:39:05.190</datetime2>');
GO

但我有错误Reference to an undefined name 'datetime2' within namespace 'http://www.w3.org/2001/XMLSchema'.与type="xsd:datetime2"相同 - 错误

Reference to an undefined name 'datetime2' within namespace 'http://schemas.microsoft.com/sqlserver/2004/sqltypes/sql2008/SqlTypes.xsd'

它假设以某种方式工作,https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/bb677236(v=sql.105(?重定向自=MSDN 中描述的类型,但不幸的是我不知道出了什么问题。

Erland Sommarskog在msdn上回答 解决方案是

CREATE XML SCHEMA COLLECTION [XmlValuesSchemaCollection_datetime2] AS 
'<?xml version="1.0"?>
<xsd:schema    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes"      attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sql2008/sqltypes.xsd"/>
<xsd:element name="datetime2" type="sqltypes:datetime2"/>
</xsd:schema>';

相关内容

  • 没有找到相关文章

最新更新