Jaa


Managing XML Schema Collections on the Server

As described in the topic, xml Data Type, SQL Server provides native storage of XML data through the xml data type. You can optionally associate XSD schemas with a variable or a column of xml type through an XML schema collection. The XML schema collection stores the imported XML schemas and is then used to do the following:

  • Validate XML instances
  • Type the XML data as it is stored in the database

Note that the XML schema collection is a metadata entity like a table in the database. You can create, modify, and drop them. Schemas specified in a CREATE XML SCHEMA COLLECTION (Transact-SQL) statement are automatically imported into the newly created XML schema collection object. You can import additional schemas or schema components into an existing collection object in the database by using the ALTER XML SCHEMA COLLECTION (Transact-SQL) statement.

As described in the topic, Typed vs. Untyped XML, the XML stored in a column or variable that a schema is associated with is referred to as typed XML, because the schema provides the necessary data type information for the instance data. SQL Server uses this type information to optimize data storage.

The query-processing engine also uses the schema for type checking and to optimize queries and data modification.

Also, SQL Server uses the associated XML schema collection, in the case of typed xml, to validate the XML instance. If the XML instance complies with the schema, the database allows the instance to be stored in the system with their type information. Otherwise, it rejects the instance.

SQL Server provides various DDL statements to manage the schemas in the database. However, you first have to import the XML schema collection before you can use it. For more information, see DDL for Managing XML Schema Collections in the Database.

To import an XML schema collection into a database, you must have permissions. For more information, see Permissions on an XML Schema Collection.

You can use the intrinsic function XML_SCHEMA_NAMESPACE to retrieve the schema collection that is stored in the database. For more information, see Viewing a Stored XML Schema Collection.

You can also use the XML schema collection to type XML variables, parameters, and columns.

See Also

Reference

DDL for Managing XML Schema Collections in the Database
Viewing a Stored XML Schema Collection
Guidelines and Limitations in Using XML Schema Collections on the Server
Permissions on an XML Schema Collection

Concepts

Preprocessor Tool for XML Schemas
Sample XML Applications

Help and Information

Getting SQL Server 2005 Assistance