XML support in Microsoft SQL Server 2005 (2)

Source: Internet
Author: User
Tags microsoft sql server microsoft sql server 2005 modify scalar xquery


XML Data modification



SQL Server 2005 provides a construct for data modification as an extension of XQuery. The subtree can be inserted either before or after the specified node, or as the leftmost or rightmost child node. In addition, a subtree can be inserted into the parent node, in which case it becomes the rightmost child node of the parent node. attributes, elements, and text node inserts are supported.



Delete Subtree is supported. In this case, the entire subtree is removed from the XML instance.



A scalar value can be replaced with a new scalar value.



Example: Inserting a subtree into an XML instance



This example shows the use of the Modify () method, which inserts a new <section> element to the right of the element numbered 1.


UPDATE docs SET xCol.modify('
 insert
  <section num="2">
     </section>        
 after (/doc/section[@num=1])[1]')



Example: Update the price of this book to $49.99



The following UPDATE statement replaces <price> of book ISBN 1-8610-0311-0 with $49.99. The XML instance is typed through the XML Schema Http://myBooksinstance and thus has a namespace declaration in the XML data modification statement.


UPDATE XmlCatalog
SET  Document.modify ('
  default namespace = "http://myBooks"
  replace value of (/bookstore/book[@ISBN=
"1-8610-0311-0"]/price)[1] with 49.99')



Type checking and static errors


XQuery introduces type checking. The compile phase examines the static type correctness of XQuery expressions and data modification statements, and uses XML schemas for type inference (in the case of typed XML). If an expression fails because of a type security violation at run time, a static type error is generated. Examples of static errors are: Adding a string to an integer, receiving a sequence of values where the operation requires a single value, and querying for nonexistent nodes to find typed data. Explicit conversion to the correct type is a workaround for static errors that result from a type mismatch. The XQuery run-time error is converted to an empty sequence.




Related Article

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.