我正在尝试在集合和表中使用SQL Server XML模式类型,如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://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/bb677236(v=sql.105)?redirectedfrom=MSDN描述的类型,但不幸的是,我不知道哪里出了问题。
发布于 2019-10-11 22:56:30
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>';https://stackoverflow.com/questions/58325019
复制相似问题