Skip to content

Commit 29bac15

Browse files
authored
xml schema article (#36749)
correct applies to backlinks
1 parent b7a7ec8 commit 29bac15

5 files changed

Lines changed: 97 additions & 3 deletions

File tree

docs/relational-databases/xml/xml-schema-collections-sql-server.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ You can query XML schemas that you have loaded into XML schema collections in th
213213

214214
- Create a table that contains an **xml** data type column to store your XML schemas and also load them into the XML type system. You can query the XML column by using the **xml** data type methods. Also, you can build an XML index on this column. However, with this approach, the application must maintain consistency between the XML schemas stored in the XML column and the XML type system. For example, if you drop the XML schema namespace from the XML type system, you also have to drop it from the table in order to preserve consistency.
215215

216-
## See also
216+
## Related content
217217

218218
- [View a Stored XML Schema Collection](../../relational-databases/xml/view-a-stored-xml-schema-collection.md)
219219
- [Preprocess a Schema to Merge Included Schemas](../../relational-databases/xml/preprocess-a-schema-to-merge-included-schemas.md)
220220
- [Requirements and Limitations for XML Schema Collections on the Server](../../relational-databases/xml/requirements-and-limitations-for-xml-schema-collections-on-the-server.md)
221-
221+
- [XML schema collections in SQL projects](../../tools/sql-database-projects/concepts/xml-schema-collection.md)

docs/t-sql/statements/create-xml-schema-collection-transact-sql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,4 @@ GO
290290
- [EVENTDATA (Transact-SQL)](../functions/eventdata-transact-sql.md)
291291
- [Compare typed XML to untyped XML](../../relational-databases/xml/compare-typed-xml-to-untyped-xml.md)
292292
- [Requirements and limitations for XML schema collections on the server](../../relational-databases/xml/requirements-and-limitations-for-xml-schema-collections-on-the-server.md)
293-
293+
- [XML schema collections in SQL projects](../../tools/sql-database-projects/concepts/xml-schema-collection.md)

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8723,6 +8723,8 @@ items:
87238723
href: tools/sql-database-projects/concepts/system-objects.md
87248724
- name: Target platform
87258725
href: tools/sql-database-projects/concepts/target-platform.md
8726+
- name: XML schema collections
8727+
href: tools/sql-database-projects/concepts/xml-schema-collection.md
87268728
- name: Data tier applications
87278729
href: tools/sql-database-projects/concepts/data-tier-applications/overview.md
87288730
items:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: SQL Projects XML Schema Collections
3+
description: "Automatic generation of XML schema collections in SQL database projects."
4+
author: dzsquared
5+
ms.author: drskwier
6+
ms.reviewer: maghan, randolphwest
7+
ms.date: 03/03/2026
8+
ms.service: sql
9+
ms.subservice: sql-database-projects
10+
ms.topic: concept-article
11+
ai-usage: ai-assisted
12+
ms.collection:
13+
- data-tools
14+
---
15+
16+
# XML schema collections in SQL projects
17+
18+
[!INCLUDE [SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB](../../../includes/applies-to-version/sql-asdb-asdbmi-fabricsqldb.md)]
19+
20+
SQL database projects support automatic generation of XML schema collection objects from XSD (XML Schema Definition) files. When you include an XSD file in your project with the appropriate metadata, the build process creates a `CREATE XML SCHEMA COLLECTION` statement that you can use to enforce XML data validation in your database.
21+
22+
XML schema collections provide typed XML columns in SQL Server, enabling the database engine to validate XML data against defined schemas and optimize query performance.
23+
24+
## Configure XSD files in the project
25+
26+
To generate an XML schema collection from an XSD file, add a `Build` item to your project file (`.sqlproj`) with two required metadata elements:
27+
28+
- **RelationalSchema**: The database schema where the XML schema collection is created (for example, `dbo`)
29+
- **XMLSchemaCollectionName**: The name of the resulting XML schema collection object in the database
30+
31+
The following example shows how to configure an XSD file in a SQL project:
32+
33+
```xml
34+
<?xml version="1.0" encoding="utf-8"?>
35+
<Project DefaultTargets="Build">
36+
<Sdk Name="Microsoft.Build.Sql" Version="2.1.0" />
37+
<PropertyGroup>
38+
<Name>MyDatabase</Name>
39+
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql170DatabaseSchemaProvider</DSP>
40+
<ModelCollation>1033, CI</ModelCollation>
41+
</PropertyGroup>
42+
<ItemGroup>
43+
<Build Include="OrderSchema.xsd">
44+
<RelationalSchema>dbo</RelationalSchema>
45+
<XMLSchemaCollectionName>OrderSchemaCollection</XMLSchemaCollectionName>
46+
</Build>
47+
</ItemGroup>
48+
</Project>
49+
```
50+
51+
## XSD file example
52+
53+
The XSD file defines the structure that XML data must follow. The following example defines a schema for an `Order` element containing one or more `Item` elements:
54+
55+
```xml
56+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
57+
<xs:element name="Order">
58+
<xs:complexType>
59+
<xs:sequence>
60+
<xs:element name="Item" type="xs:string" maxOccurs="unbounded"/>
61+
</xs:sequence>
62+
</xs:complexType>
63+
</xs:element>
64+
</xs:schema>
65+
```
66+
67+
When the project builds, this XSD file generates a `CREATE XML SCHEMA COLLECTION` statement that creates the `OrderSchemaCollection` object in the `dbo` schema.
68+
69+
## Use typed XML columns
70+
71+
After the XML schema collection is defined, reference it in table definitions to create typed XML columns. Typed XML columns validate data against the schema and improve query performance.
72+
73+
The following example creates a table with a typed XML column that uses the generated schema collection:
74+
75+
```sql
76+
CREATE TABLE dbo.Orders (
77+
Id INT PRIMARY KEY,
78+
OrderData XML(dbo.OrderSchemaCollection)
79+
);
80+
```
81+
82+
When you insert data into the `OrderData` column, SQL Server validates the XML against the `OrderSchemaCollection` schema. Invalid XML that doesn't conform to the schema is rejected.
83+
84+
## Related content
85+
86+
- [XML schema collections (SQL Server)](../../../relational-databases/xml/xml-schema-collections-sql-server.md)
87+
- [XML data (SQL Server)](../../../relational-databases/xml/xml-data-sql-server.md)
88+
- [Project properties](project-properties.md)

docs/tools/sql-database-projects/howto/add-existing-files-to-sql-project.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ There are known issues where the script processing might result in duplicate con
6666

6767
The Import from Script process doesn't incorporate Pre/Post-Deployment scripts, SQLCMD variables, or RefactorLog files. These and any other unsupported constructs that are detected on import are placed in a ScriptsIgnoredOnImport.sql file in a Scripts folder in your project.
6868

69+
## XSD files
70+
71+
SQL projects also support importing XSD files to generate XML schema collections in the database. For more information on how to configure XSD files in a SQL project, see [XML schema collections in SQL projects](../concepts/xml-schema-collection.md).
72+
6973
## Related content
7074

7175
- [Tutorial: start from an existing database](../tutorials/start-from-existing-database.md)

0 commit comments

Comments
 (0)