08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
XML Data Types in the Real World
1. XML Data Type Methods
In the Real World
Steve Hughes
Senior Data Architect, XATA Corporation
2. Agenda
• Overview of XML in SQL Server 2005
• A Case for Using XML in SQL Server
• Brief Introduction to the XML Data Type
• XML Data Type Methods with Demos
• Lessons Learned
AD-307 • XML Data Type Methods in the Real World
3. Overview of XML in SQL Server 2005
• XML Data Type
• XML Data Type Methods
• XML Schema Collections
• XQuery
• This allows direct support of XQuery in the .NET Framework
• OPENXML and FOR XML
• Various improvements in SQL Server 2005
• OPENROWSET
• Used for bulk operation and was improved in SQL Server 2005
as well
AD-307 • XML Data Type Methods in the Real World
4. A Case for Using XML in SQL Server
• Implementing Multidimensional Arrays
• Relating multiple unrelated types of data
• Service Broker implementation
• Extracting XML messages from the broker in the activation
stored procedure or procedures called by the activation stored
procedure
• Use in place of comma separated lists
• Common implementation when sending parameters with multiple
values
AD-307 • XML Data Type Methods in the Real World
5. Introducing XML Data Type Methods
• XML Data Type Methods work against the SQL Server
XML data type within SQL
• They work with typed and untyped XML
• They work with XML Variables and Columns
• These methods extract or manipulate XML data
• Uses XQuery syntax
• Methods
• query
• value
• exist
• modify
• nodes
AD-307 • XML Data Type Methods in the Real World
6. Query()
• Description
• Allows you to select data out of the XML data type variable or
column
• Returns XML
• Syntax
• query(‘XQuery’)
• Demo
AD-307 • XML Data Type Methods in the Real World
7. Value()
• Description
• Use this method to query for a scalar value out of the XML
• It returns most SQL Data Types, the exceptions are:
• xml
• image
• text
• ntext
• sql_variant
• Syntax
• value(‘XQuery’, ‘SQL Data Type’)
• Demo
AD-307 • XML Data Type Methods in the Real World
8. Exist()
• Description
• Works similar to the EXISTS statement in T-SQL
• Returns 1 if the XQuery returns a result
• Syntax
• exist(‘XQuery’)
• Demo
AD-307 • XML Data Type Methods in the Real World
9. Modify()
• Description
• This method modifies the content of the xml document
• It can insert, delete and replace values
• This method can only be used in the SET clause of an UPDATE
statement
• This method uses XML Data Manipulation Language (DML) to
modify the document
• Syntax
• modify(‘XML_DML’)
• Demos
• insert
• delete
• replace value of
AD-307 • XML Data Type Methods in the Real World
10. Nodes()
• Description
• This method is used to shred XML data into relational data
• This method returns the data as rowset that can be used like a
table in T-SQL.
• Syntax
• nodes(‘XQuery’) as Table(Column)
• Demo
AD-307 • XML Data Type Methods in the Real World
11. Using the CROSS APPLY operator
• The APPLY operator allows you to apply a table function
to a rowset and return the values as a single result set of
both sets of data
• CROSS APPLY returns the matching records
• Used with the nodes() method and a XML Data Type
column, you can return shredded XML data with the
relational data from the same table
• Demo
AD-307 • XML Data Type Methods in the Real World
12. Demonstration
Real world implementations
• Parameter for a Stored Procedure
• Used to interpret messages from Service Broker
AD-307 • XML Data Type Methods in the Real World
13. Lessons Learned
• Setting options SET Options Required Values
that must be ANSI_NULLS ON
applied ANSI_PADDING ON
• Always work with ANSI_WARNINGS ON
ARITHABORT ON
the developers on
CONCAT_NULL_YIELD_NULL ON
the XML syntax NUMERIC_ROUNDABORT OFF
• If you have not QUOTED_IDENTIFIER ON
used XML much, there is a learning curve, be sure to
account for it.
• It can be difficult to tune queries with XML methods
AD-307 • XML Data Type Methods in the Real World
14. Tuning and Performance
• Caveat: This is related to using XML data type for
passing parameters
• Memory pressure was expected, but not present
• CPU can be heavily utilized for large parsing operations
• Execution plan shows a Table Valued Function for each
method you use
• Indexes can only be used if the data in the table
• Using schemas will usually hurt performance in this
scenario as it adds another layer of work for the parser
• Couple of Performance demos
Session Code • Session Title
16. Additional Resources
• SQL Server 2005 Books Online
• Search for XML Data Type
• MSDN.microsoft.com
• Performance Optimizations for the XML Data Type in SQL
Server 2005 http://msdn2.microsoft.com/en-us/library/ms345118.aspx
• http://blogs.msdn.com/spal/default.aspx
• Using XML Data Type Methods to query SSIS Packages
• http://sqlblog.com/blogs/peter_debetta/archive/2006/07/13/Using
_XML_Data_Type_Methods_to_query_SSIS_Packages.aspx
• Michael Rys’s blog – Musings on XML, XQuery and
more – He has links to multiple related whitepapers
• http://sqljunkies.com/weblog/mrys/
AD-307 • XML Data Type Methods in the Real World
17. Thank you!
Thank you for attending this session and the
2007 PASS Community Summit in Denver
AD-307 • XML Data Type Methods in the Real World
Notas do Editor
Store Aisle with Groceries The aisle never changes The groceries are stored in the XML column Request is to see what aisle each grocery type is in CROSS APPLY allows us to break ou the