The following is an example of how to create an XML Schema in SQL Server.
1: -- DROP IF EXISTS
2: IF EXISTS (SELECT 1
3: FROM sys.xml_schema_collections
4: WHERE name='SampleSchema')
5: DROP XML SCHEMA COLLECTION SampleSchema
6:
7: CREATE XML SCHEMA COLLECTION SampleSchema AS
8: '<?xml version="1.0" encoding="utf-8"?>
9: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
10: <xsd:element name="Sample">
11: <xsd:complexType>
12: <xsd:attribute name="SampleID" type="xsd:integer" />
13: <xsd:attribute name="Name" type="xsd:string" />
14: <xsd:attribute name="Description" type="xsd:string" />
15: </xsd:complexType>
16: </xsd:element>
17: </xsd:schema>'
To check your XML Schema:
Method 1: Go to your database > Programmability > Types > XML Schema Collections
Method 2: You can use the xml_schema_namespace function to query the schema from within SSMS
1:
2: SELECT
3: xml_schema_namespace(N'dbo',N'SampleSchema')
Later on I will post additional sample schemas which use different SQL XML data types.
Related posts:
- SQLXML : How to Alter Existing Column Schema (XSD) ...
- SQLXML : How to List Schema Elements and Attributes ...
- SQLXML : How to Check if an XML Schema Already Exists ...
- SQLXML : How to Use SQL Server XML Function exist() ...
- SQLXML : How to Join Multiple XML Snippets (using query() and UNION ALL) ...
- The Case of the Missing Create GUID Tool (guidgen.exe) from Visual Studio 2005 ...
Filed under:
SQLXML











Leave a comment