Database Reference
In-Depth Information
style sheet ile, a .xsl ile, which provides a set of formatting information about our XML data.
Currently, the W3 Consortium splits xsl into two parts, the document transformation part XSLT
for formatting and transforming XML documents to HTML and the formatting object part
XSL-FO for more sophisticated formatting.
Now that some basic concepts about XML have been introduced, next you will learn about the
XML data type and how to store XML data in a database. After that, you will learn how to query
XML data with XQuery and display the content by applying the XSLT style sheet.
5.7.2 XML Data Type
SQL Server supports the XML data type, which allows users to store XML documents natively. You
can use the XML data type just like you use a data type such as INT or NVARCHAR. he XML
data type can be used to declare a variable or to deine a column in a CREATE TABLE SQL state-
ment. It can also be used to deine the input or output parameters for stored procedures and functions.
Documents deined by the XML data type can be managed with DDL SQL statements. he limita-
tion of the XML data type is that you cannot use an XML column as a primary key or foreign key.
he way of declaring an XML variable or an XML column is the same as declaring a Transact-
SQL variable or column. For example, to add a new XML column to the table CUSTOMER, use
the following SQL statement:
ALTER TABLE CUSTOMER
ADD Email XML
In the ADD clause, there is no schema collection name; this means that the column Email will
not use a schema to validate the XML content. herefore, we have just added an untyped XML
column. You can also declare an XML variable, assign a well-formed XML document to the vari-
able, and then store the XML document in the XML column. he following is the SQL statement
to accomplish these tasks:
DECLARE @email xml
SET @email = ' < Email Email = "myemail@yahoo.com"/ > '
UPDATE CUSTOMER
SET Email = @email
WHERE CustomerID = 1
You can also insert xml data into a table that has XML columns as shown in the following
activity. Besides the untyped XML data, there are typed XML data that are associated with a
schema ile, which deines the elements and attributes, and speciies the namespace. To use the
typed XML data type, you must irst create a schema ile and register the ile in an XML schema
collection. Since, at this point, Windows Azure SQL Database does support the typed XML data
type, the untyped XML data type will be the main focus of this section.
ACTIVITY 5.6 STORING XML DATA IN WINDOWS AZURE SQL DATABASE
In this activity, you will learn how to create and store untyped XML data. We will create
e-mail addresses based on customers' irst names and last names, and then insert the e-mail
addresses into the CUSTOMER table.
 
Search WWH ::




Custom Search