30.06.2013 Views

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7: Special Datatypes and <strong>Execution</strong> <strong>Plans</strong><br />

As you can see, it's easy to bring XML data into the database for use within your queries,<br />

or for inclusion within your database. As discussed previously, OPENXML is a useful<br />

tool for importing the semi-structured data within the XML documents into the wellmaintained<br />

relational database structure. It can also allow you to pass in data for other<br />

uses. For example, you can pass in a list of variables to be used as a join in a SELECT<br />

statement. The main point to take away is that once the OPENXML has been formatted,<br />

you get to use it as if it were just another table within your queries.<br />

One caveat worth mentioning is that parsing XML uses a lot of memory. You should<br />

plan on opening the XML, getting the data out, and then closing and de-allocating the<br />

XML parser as soon as possible. This will reduce the amount of time that the memory is<br />

allocated within your system.<br />

XQuery<br />

Along with the introduction of the XML data type in <strong>SQL</strong> <strong>Server</strong> 2005, came the introduction<br />

of XQuery as a method for querying XML data. Effectively, the inclusion of<br />

XQuery means a completely new query language to learn in addition to T-<strong>SQL</strong>. The XML<br />

data type is the mechanism used to provide the XQuery functionality through the <strong>SQL</strong><br />

<strong>Server</strong> system. When you want to query from the XML data type, there are five basic<br />

methods, each of which is reflected in execution plans in different ways.<br />

• .query() – Used to query the XML data type and return the XML data type.<br />

• .value() – Used to query the XML data type and return a non-XML scalar value.<br />

• .nodes() – A method for pivoting XML data into rows.<br />

• .exist() – Queries the XML data type and returns a Bool to indicate whether or not<br />

the result set is empty, just like the EXISTS keyword in T-<strong>SQL</strong>.<br />

• .modify() – A method for inserting, updating and deleting XML snippets within the<br />

XML dataset.<br />

271

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!