SQL XML(个人收藏).docx
上传人:qw****27 上传时间:2024-09-12 格式:DOCX 页数:8 大小:76KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

SQL XML(个人收藏).docx

SQLXML(个人收藏).docx

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

FORXML子句有四种最基本的模式,如上图所示:1、AUTO模式:返回数据表为起表名的元素,每一列的值返回为属性;2、RAW模式:返回数据行为元素,每一列的值作为元素的属性;3、PATH模式:通过简单的XPath语法来允许用户自定义嵌套的XML结构、元素、属性值4、EXPLICIT模式:通过SELECT语法定义输出XML的结构具体实例如下:1、AUTO模式(1).SQL语句:1:SELECTEmployeeID,FirstName,LastNameFROMEmployeesFORXMLAUTO,XMLSCHEMA(2).所生成的XML文件:返回XML文件的XMLSchema<xsd:schematargetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet1"xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet1"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes"elementFormDefault="qualified"><xsd:importnamespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes"schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd"/><xsd:elementname="Employees"><xsd:complexType><xsd:attributename="EmployeeID"type="sqltypes:int"use="required"/><xsd:attributename="FirstName"use="required"><xsd:simpleType><xsd:restrictionbase="sqltypes:nvarchar"sqltypes:localeId="1033"sqltypes:sqlCompareOptions="IgnoreCaseIgnoreKanaTypeIgnoreWidth"sqltypes:sqlSortId="52"><xsd:maxLengthvalue="10"/></<SPAN>xsd:restriction></<SPAN>xsd:simpleType></<SPAN>xsd:attribute><xsd:attributename="LastName"use="required"><xsd:simpleType><xsd:restrictionbase="sqltypes:nvarchar"sqltypes:localeId="1033"sqltypes:sqlCompareOptions="IgnoreCaseIgnoreKanaTypeIgnoreWidth"sqltypes:sqlSortId="52"><xsd:maxLengthvalue="20"/></<SPAN>xsd:restriction></<SPAN>xsd:simpleType></<SPAN>xsd:attribute></<SPAN>xsd:complexType></<SPAN>xsd:element></<SPAN>xsd:schema><Employeesxmlns="urn:schemas-microsoft-com:sql:SqlRowSet1"EmployeeID="1"FirstName="Nancy"LastName="Davolio"/><Employeesxmlns="urn:schemas-microsoft-com:sql:SqlRowSet1"EmployeeID="2"FirstName="Andrew"LastName="Fuller"/><Employeesxmlns="urn:schemas-microsoft-com:sql:SqlRowSet1"EmployeeID="3"FirstName="Janet"LastName="Leverling"/><Employeesxmlns="urn:schemas-microsoft-com:sql:SqlRowSet1"EmployeeID="4"FirstName="Margaret"LastName="Peacock"/><Employeesxmlns="urn:schemas-microsoft-com