SQL Server 2008中有关XML的新功能
有了schema中的这个声明,任何基于productSizeType 的元素都可以包含任何种类的列表;所以下面示例中的两种产品元素都是productSizeType数据类型的有效的实例。
| <Catalog>
<Product> <ProductName>Road Bike</ProductName> 网页教学网 <AvailableSizes>22 24</AvailableSizes> </Product> <Product> Webjx.Com <ProductName>Cycling <AvailableSizes>S M L</AvailableSizes> 网页教学网 </Product> </Catalog> |
类似的,SQL Server 2008支持对包含union 类型的list 类型的schema 声明。
4 增强了XQuery Webjx.Com
SQL Server 2005推出了xml 数据类型,它提供了一些你可以使用的方法来对存储在一个列或变量中的XML数据进行操作。你可以执行的大多数操作都使用XQuery语法来操纵和使用XML数据。SQL Server 2005所支持的XQuery 语法包括被称作FLWOR 表达式的for、where、order by和return 条件子句,你可以使用它来循环迭代一个XML文档的节点和返回结果值。
SQL Server 2008增加了对let条件子句的支持,它是用来在XQuery表达式中对变量进行赋值的,例如下面的示例:
| declare @x xml
set @x= '<Invoices> <Invoice> <Customer>Kim Abercrombie</Customer> <Items> Webjx.Com <Item ProductID="2" Price="1.99" Quantity="1" /> <Item ProductID="3" Price="2.99" Quantity="2" /> 网页教学网 <Item ProductID="5" Price="1.99" Quantity="1" /> 网页教学网 </Items> Webjx.Com
</Invoice> Webjx.Com <Invoice> <Customer>Margaret Smith</Customer> <Items> <Item ProductID="2" Price="1.99" Quantity="1"/> Webjx.Com </Items> 网页教学网
</Invoice> Webjx.Com </Invoices>' SELECT @x.query( '<Orders> 网页教学网 { for $invoice in /Invoices/Invoice Webjx.Com
let $count :=count($invoice/Items/Item) order by $count Webjx.Com
return Webjx.Com <Order> {$invoice/Customer} <ItemCount>{$count}</ItemCount> 网页教学网
</Order> } </Orders>') |






文章评论
共有 0 位网友发表了评论 查看完整内容