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.