SQL Server2005 XML data type Base article

Source: Internet
Author: User

First, the introduction

Today, in SQL Server 2005, XML is a first-class data type. With strongly typed support based on XML schemas and server-side XML data validation, developers can now easily modify stored XML documents remotely.

As a database developer, many people have to involve XML in large numbers.

Today, in SQL Server 2005, you can store XML in a database in the form of a new data type.

In fact, some of the XML features are already included in SQL Server 2000. Among them, the most critical feature is the use of the FOR XML statement to return the results in XML form. The functionality of SQL Server 2005 is significantly different. In SQL Server 2005, XML is a true data type; This means that you can use XML as a column in tables and views, and XML can be used in T-SQL statements or as parameters for stored procedures. Now you can store, query, and manage XML files directly in the database.

More importantly, you can now also specify the patterns that your XML must follow.

In SQL Server 2005, in addition to providing a mechanism to validate the XML types in your database, it also allows you to describe the complex data types to be stored and to provide an engine to enforce these rules.

Ii. use of XML data types

In fact, there is no fundamental difference between the XML data type and other data types in SQL Server. You can use it in any normal SQL data type place. For example, the following statement creates an XML variable and populates it with an XML:

DECLARE @doc xml
SELECT @doc = '<Team name="Braves" />'

Alternatively, you can populate an XML variable with a query and SQL Server FOR XML syntax:

SELECT @doc =
(SELECT * FROM Person.Contact FOR XML AUTO)

XML data types can be used not only as variables, but also in table columns. You can also assign default values and support NOT NULL constraints:

CREATE TABLE Team
(
TeamID int identity not null,
TeamDoc xml DEFAULT '<Team />' NOT NULL
)

Note: SQL Server 2005 has an obvious difference in XML functionality from SQL Server 2000.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.