xquery删除_XQuery实例删除SQL XML文档

xquery删除

Delete operations over SQL XML should be possible with either erasing the XML document with the XML data type column or delete XML tag or attribute in the XML document using XQuery. The utilization of the XML data type with XQuery is tricky and significant in SQL Server.

通过使用XML数据类型列擦除XML文档或使用XQuery删除XML文档中的XML标签或属性,应该可以对SQL XML进行删除操作。 XQuery对XML数据类型的利用在SQL Server中非常棘手,意义重大。

Form to XML
Reset the details of the particular form, one of these activities need to a .

表单到XML
重置特定表格的详细信息,这些活动之一需要。

In this article, we will show you how to delete XML nodes from a SQL XML Document in different ways. Here is the sample XML Document to demonstrate various XML delete tag operation.

在本文中,我们将向您展示如何以不同方式从SQL XML文档中删除XML节点。 这是示例XML文档,用于演示各种XML删除标记操作。

<ns:Resume xmlns:ns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume">
  <ns:Name>
    <ns:Name.Prefix>Mr.</ns:Name.Prefix>
    <ns:Name.First>Max</ns:Name.First>
    <ns:Name.Middle></ns:Name.Middle>
    <ns:Name.Last>Benson</ns:Name.Last>
    <ns:Name.Suffix></ns:Name.Suffix>
  </ns:Name>
  <ns:Employment>
    <ns:Emp.StartDate>1994-06-15Z</ns:Emp.StartDate>
    <ns:Emp.OrgName>Wingtip Toys</ns:Emp.OrgName>
    <ns:Emp.JobTitle>Production Manager</ns:Emp.JobTitle>
    <ns:Emp.Responsibility>Production manager Quality assurance lead Safety representative ISO 9000 certification lead
Production line worker
        </ns:Emp.Responsibility>
    <ns:Emp.FunctionCategory>Production</ns:Emp.FunctionCategory>
    <ns:Emp.IndustryCategory>Manufacturing</ns:Emp.IndustryCategory>
    <ns:Emp.Location>
      <ns:Location>
        <ns:Loc.CountryRegion>US </ns:Loc.CountryRegion>
        <ns:Loc.State>FL </ns:Loc.State>
        <ns:Loc.City>Orlando</ns:Loc.City>
      </ns:Location>
    </ns:Emp.Location>
  </ns:Employment>
</ns:Resume>

This SQL XML with client information will be related to each row in the table HumanResources.

带有客户端信息的此SQL XML将与表HumanResources中的每一行相关。

Delete the value in the XML tag and Delete the XML tag in the XML data type column, both are altogether different things. We will show an example with sample data as below.

删除XML标记中的值和XML数据类型列中的删除XML标记,两者是完全不同的。 我们将显示一个带有示例数据的示例,如下所示。

删除SQL XML文档中的XML标签或节点 (Delete XML Tag or Node in the SQL XML document)

When a user needed to delete the XML tag or node in the document, then this below sample can be useful. Using the “.modify” function will delete the XML tag utilizing the target node path with the index value in the XQuery. Parameters of the XQuery are, what conditions do you have to meet to remove a particular node? What rules would you be following to delete the particular nodes?

当用户需要删除文档中的XML标记或节点时,下面的示例非常有用。 使用“ .modify”功能将利用目标节点路径和XQuery中的索引值来删除XML标记。 XQuery的参数是,删除特定节点必须满足什么条件? 您将遵循哪些规则删除特定节点?

SET @XMl_doc.modify ('delete (/*:Resume/*:Name/*:Name.Last)[1]')

SQL XML after Query Execution:

执行查询后SQL XML:

<ns:Resume xmlns:ns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume">
  <ns:Name>
    <ns:Name.Prefix>Mr.</ns:Name.Prefix>
    <ns:Name.First>Max</ns:Name.First>
    <ns:Name.Middle />
    <ns:Name.Suffix />
  </ns:Name>
…

Here, the above sample query is deleting the XML tag, which is existing on a derived path in the .modify function with delete keyword. The index of the Element tag is referenced to action on target SQL XML tag with the XML path in the document. Therefore, Target XML node should be defined with the accurate element index in the XQuery to delete the exact SQL XML tag. Element id in bracket [] represents that the order position of the XML tag in the XPATH. It helps when multiple tags are existing with the same XML tag name. When a user does not mention the element index with the XML node in XQuery, then multiple XML tags can be deleted, which exist on the derived XPATH in the SQL XML.

在这里,上述示例查询正在删除XML标记,该标记存在于.modify函数中带有delete关键字的派生路径上。 Element标签的索引被引用以对具有文档中XML路径的目标SQL XML标签执行操作。 因此,应在XQuery中使用准确的元素索引定义Target XML节点,以删除准确SQL XML标记。 括号[]中的元素id表示XML标记在XPATH中的顺序位置。 当存在多个具有相同XML标记名称的标记时,它会有所帮助。 当用户没有在XQuery中使用XML节点提及元素索引时,则可以删除多个XML标记,这些标记存在于SQL XML的派生XPATH中。

删除XML数据类型文档中的XML标记值 (Delete XML Tag value in XML data type document)

When a client needed to remove just value which exists in the particular XML tag or node in the SQL XML document and not to remove the tag, then this underneath sample can be helpful. XML Element value will be erased utilizing the text() with the delete keyword in modify() function.

当客户端需要删除SQL XML文档中特定XML标记或节点中存在的值而无需删除标记时,此示例下面的内容可能会有所帮助。 XML元素值将通过使用text()和Modify()函数中的delete关键字来擦除。

SET @XMl_doc.modify ('delete (/*:Resume/*:Name/*:Name.Last/text())')
<ns:Resume xmlns:ns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume">
  <ns:Name>
    <ns:Name.Prefix>Mr.</ns:Name.Prefix>
    <ns:Name.First>Max</ns:Name.First>
    <ns:Name.Middle />
    <ns:Name.Last />
    <ns:Name.Suffix />
  </ns:Name>
…

Here, the above example XQuery is to delete the value of Name.Last element in the SQL XML. A query is deleting just value, which exists in the referenced path in .modify function. So after deleting the value using delete in the modify() function, blank tag <ns:Name.Last /> will exist in the XML document.

在这里,上面的XQuery示例是删除SQL XML中Name.Last元素的值。 查询将删除.modify函数的引用路径中存在的值。 因此,在modify()函数中使用delete删除值之后,空白标记<ns:Name.Last />将存在于XML文档中。

In this above sample, a namespace is used with each XML tag in the XML data type column. A namespace is a major subject itself in the XML with SQL Server. To deal with the namespace in the XQuery, little query syntax will be changed. /*: should be added before every node in the XML path in any XML Query.

在以上示例中,名称空间与XML数据类型列中的每个XML标记一起使用。 命名空间本身就是带有SQL Server的XML中的主要主题。 为了处理XQuery中的名称空间,几乎不会更改查询语法。 / *:应在任何XML查询的XML路径中的每个节点之前添加。

If a namespace is not defined or does not exist in the XML document, then the XML path will be used with / to separate the XML tags or nodes. For instance, the below XQuery illustration is equivalent to the first example to delete the XML node in the XML document.

如果未定义名称空间或XML文档中不存在名称空间,则XML路径将与/一起使用以分隔XML标签或节点。 例如,下面的XQuery插图等效于删除XML文档中的XML节点的第一个示例。

SET @XMl_doc.modify ('delete (/Resume/Name/Name.Last)[1]')

Here, we used only / in the XML path /Resume/Name/Name.Last.

在这里,我们仅在XML路径/Resume/Name/Name.Last中使用/。

DELETE SQL XML element and element value – both ways are being used in the different case requirements and nature of the data. When a user is deleting the field in the XML data type document, then the above XQuery example is useful. When a SQL XML tag value is deleted and again the user wants to insert a new value in that XML tag, then XML needs that blank node in the XML document to fill it once again. In that case, the second alternative, delete in .modify with text(), would be helpful within XQuery.

DELETE SQL XML元素和元素值–两种方式都用于不同的大小写要求和数据性质。 当用户删除XML数据类型文档中的字段时,上述XQuery示例将非常有用。 当删除SQL XML标记值并且用户再次想要在该XML标记中插入新值时,则XML需要XML文档中的空白节点再次填充它。 在这种情况下,第二种选择是使用text()在.modify中删除,这在XQuery中很有用。

删除SQL Server表中的XML文档 (Delete XML document in the SQL Server table)

In such cases, the requirement can be to delete the existing XML document from the row of the table. What can be an alternate way and use case?

在这种情况下,要求可能是从表的行中删除现有的XML文档。 有什么替代方法和用例?

  1. Replace a blank XML template with the existing XML document

    用现有的XML文档替换空白的XML模板
  2. Delete a row in the table

    删除表格中的一行
  3. Keep blank value on the XML column for the row in the row

    在该行的XML列上保留空白值

Replace blank XML template with the existing XML document approach can be used when the user taps on the Form Reset activity in the application. That implies, all XML elements which exist in the XML document will be deleted and only lookup tags can exist. Lookup fields and default XML tags filled with default value in the XML document if required.

当用户点击应用程序中的“表单重置”活动时,可以使用现有XML文档方法替换空白XML模板。 这意味着,将删除XML文档中存在的所有XML元素,并且只能存在查找标记。 如果需要,查找字段和默认XML标记会填充XML文档中的默认值。

UPDATE xml_table
SET xml_table.xml_data = xml_template.xml_data
FROM xml_table
INNER JOIN xml_template ON xml_table.template_id =  xml_template.template_id
WHERE id = ?

RESET FORM

Here, xml_table is replacing the XML document from the table xml_template dependent on the XML template_id of the existing XML. A table can contain numerous sorts of forms, and even, it can have various templates in the xml_template table.

在这里,xml_table依赖于现有XML的XML template_id从表xml_template替换XML文档。 一个表可以包含多种形式,甚至可以在xml_template表中包含各种模板。

Deleting a row with XML is the same as regular delete statements to delete a row from the table. In any case, delete operation with XML can take a little more time rather than normal delete operation. Because XML is a LOB data type in SQL Server, which consumes more space than other data types. However, more server assets will be utilized to execute the statement and a little longer to perform the write operation in the file system as well.

使用XML删除行与从表中删除行的常规delete语句相同。 在任何情况下,使用XML进行删除操作都比正常的删除操作花费更多时间。 因为XML是SQL Server中的LOB数据类型,所以它比其他数据类型消耗更多的空间。 但是,将使用更多的服务器资产来执行该语句,并花费一点时间来在文件系统中执行写操作。

In such scenarios, the XML column needs to be blank. Therefore, that column will be replaced with NULL or ” in the row of the table. But never use the replace function to assign ” value to the row of the table. That activity required on the platform when confidential or private information is deleting from the system and doesn’t want to keep in the product. However, as the audit standards of the system that rows need to exist in the database. Therefore, that XML document will be replaced with the blank or NULL in the SQL Server.

在这种情况下,XML列需要为空。 因此,该列将在表的行中替换为NULL或”。 但切勿使用replace函数将“”值分配给表的行。 当机密信息或私人信息从系统中删除并且不想保留在产品中时,平台上需要执行的活动。 但是,作为系统的审核标准,数据库中必须存在行。 因此,该XML文档将在SQL Server中替换为空白或NULL。

For example:

例如:

UPDATE xml_table
SET xml_table.xml_data = ''
WHERE id = ?

In this article, the above XQuery examples explain to delete and replace the value of different XML nodes inside XML, where the replacement XML node value operation can happen more than once in the SQL XML document. This article will give a better understanding of the learning extension over the SQL XML.

在本文中,以上XQuery示例说明了删除和替换XML内部不同XML节点的值的情况,其中替换XML节点值的操作在SQL XML文档中可能会发生多次。 本文将更好地理解SQL XML上的学习扩展。

翻译自: https://www.sqlshack.com/xquery-examples-to-delete-sql-xml-documents/

xquery删除

24、使用 SQL Server 服务器端技术检索 XML 数据 本文详细介绍了如何使用 SQL Server 服务器端技术检索和操作 XML 数据。内容包括 FOR XML 的使用、XML 数据类型方法(query(), value(), exist() 等)、XQuery 和 XPath 的基本概念以及 FLWOR 表达式的构建。同时,通过实际案例展示了如何在 UniversalLog 表中进行 XML 查询和转换,并提供了多个复习问题帮助巩固相关知识点。 阅读详情

相关推荐

ZYNQ专题-7020驱动KSZ9031 PHY芯片

之所以有这篇文章,得益于Alinx的开发板。

Anitawen的博客 4979

sql删除xml基本写法

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.keyou.dao.userM...

phillip629的博客 3559

[附源码]计算机毕业设计Python财务管理系统(程序+源码+LW文档)

该项目含有源码、文档、程序、数据库、配套开发软件、软件安装教程项目运行环境配置:Pychram社区版+py项目技术:django + python+ Vue 等等组成,B/S模式 +pychram管理等等。环境需要1.运行环境:最好是python3.7.7,我们在这个版本上开发的。其他版本理论上也可以。2.pycharm环境:pycharm都可以。推荐pycharm社区版;3.mysql环境:建议是用5.7版本均可。

巧灵计算机程序设计 1071

新增或删除XML,根据条件删除重复数据

<insert id="saveOrUpdate" parameterType="CmsStatisticsModel"> <selectKey keyProperty="count" resultType="int" order="BEFORE"> select count(*) as count from cms_user_statistics where user_id = #{userId} </selectKey

我很丑的博客 242

《生化危机9:安魂曲》D加密免BIOS破解方案详解

数字版权管理(DRM)技术通过加密手段保护软件版权,Denuvo(D加密)作为主流方案常应用于3A游戏。其原理是通过实时验证机制阻止未授权访问,但可能影响性能表现。本文以《生化危机9》为例,解析一种免BIOS修改的D加密绕过方案,该方案通过授权启动器模拟正版验证流程,保持系统零侵入性。实测表明,该方法在GTX 1060至RTX 3070等多硬件平台均能稳定运行,支持MOD扩展且兼容Reshade画质增强,为玩家提供开箱即用的绿色版体验。

weixin_33898233的博客 935

std::map看来可以被淘汰了?可以用vector来替代,而且更好

vector的优势在于内存连续,可以先std::sort,然后std::lower_bound,或者std::binary_search。而std::map,insert的时候,需要new出内存。

tumu_C的博客 1025

SQLServer XML数据的五种基本操作

一、前言 从 SQL Server 2005 开始,就增加了 xml 字段类型,也就是说可以直接把 xml 内容存储在该字段中,并且 SQL Server 会把它当作 xml 来对待,而不是当作 varchar 来对待。 随着SQL Server 对XML字段的支持,相应的,T-SQL语句也提供了大量对XML操作的功能来配合SQL Server中XML字段的使用。本文主要说明如何使用SQL语句对XML进行操作。 二、定义XML字段 在进行数据库的设计中,我们可以在表设计器中,很方...

GuoGuoABC 3941

Ubutntu下使用realsense d435i(二):获取某二维像素点的三维坐标

00 准备工作 准备工作包括安装驱动以及pyrealsense2,具体可参考上一篇: Ubutntu下使用realsense d435i(一):准备工作以及安装pyrealsense2 https://blog.csdn.net/gyxx1998/article/details/121461293 01 通过二维像素点获得物体三维坐标 这个在上一篇已经介绍了代码: realsense d435i获取某像素点三维坐标(计算深度和点云两种方法) https://blog.csdn.net/gyxx1998/

gyxx1998的博客 9946

Xquery增删改

XML更新 SQL语句 [code="sql"] update customer set info =''where xmlexists (declare default element namespace ".org";$doc/customerinfo[@Cid=222]) [/code] Xquery语句 [code="sql"] UPDATE customer set in...

wzl454823的博客 310

直流无刷减速电机选型指南:从KV值到霍尔传感器,新手必看的5个关键参数

本文详细解析直流无刷减速电机选型的5个关键参数,包括KV值、转矩、电流与功率、减速比选择以及霍尔传感器配置。通过实战案例和避坑策略,帮助工程师精准匹配电机性能与负载需求,提升工业自动化设备的可靠性和效率。特别强调霍尔传感器在精准控制中的关键作用。

alice7model的博客 627

【电路设计】带阻滤波器实战:从理论到Twin-T陷波电路实现

本文详细介绍了带阻滤波器的原理与Twin-T陷波电路的实战应用,从基础概念到工程实现全面解析。通过具体案例展示如何设计高Q值滤波器,解决电源噪声等实际问题,并分享PCB布局和元件选型的实用技巧,助力工程师提升电路设计能力。

gg901的博客 1030

XPath、XQuery 以及 XSLT 函数

  存取函数名称说明fn:node-name(node)返回参数节点的节点名称。fn:nilled(node)返回是否拒绝参数节点的布尔值。fn:data(item.item,...)接受项目序列,并返回原子值序列。fn:base-uri() fn:base-uri(node)返回当前节点或指定节点的 base

Ivan Song的专栏 1364

通过电源模块降低电源噪声的3种方法

电源噪声是一种常见且不受欢迎的电气现象。如果不降低噪声,其会对敏感的医疗、测试测量、航空航天和国防系统的应用性能产生不利影响。当今的高精度模拟信号链系统需要直流/直流开关稳压器产生稳压电源轨,为低噪声应用中的模数转换器(ADC)、数模转换器(DAC)、现场可编程门阵列(FPGA)及其子系统供电。尽管直流/直流开关稳压器具有高工作效率,它们的开关操作会导致较大的不连续电流,从而产生较高的输入和输出电压纹波、频率尖峰和宽带噪声。

qq_43416206的博客 1432

xquery_在SQL Server中使用XQuery更新XML的不同方法

xquery XQuery is a query language for XML. XML is a markup language that provides software and hardware-independent way of storing, transporting, and sharing data. In this case, XML documents are s...

culuo4781的博客 925

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

上手DB2的xml(1)

接触DB2的第12天,因为工作任务的需要,开始接触XML的一些东西了,之前看的XML的一些百度相关的东西大致知道了XML是怎么样一个东西,其实因为json永久了蛮嫌弃xml的,然后知乎上说xml是面向机器的,对于机器来说结构很好,其实我觉得json就蛮好的,先来接触一下xml再来说二者的是非吧。 那我的需求是表中有xml字段,xml字段中有节点,那如果是json的话,我可以使用字段名->’键名

nayanminxing的专栏 2498

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

SQL Server 2005 XML 操作总结(八)属性操作——删除、遍历操作

======删除操作============== --删除title的lang="en"且 price&gt;35的所有book的category属性set @data.modify('delete bookstore/book[./title[@lang="en"] or price&gt;35 ]/@category') /*output:<bo...

weixin_33866037的博客 185

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

XML操作

create table docs (  pk int primary key,  Xcol xml not null ) declare @xmlDoc xml set @xmlDoc=' C program David 21 ' insert into docs values(1,@xmlDoc) select * from docs -- 查询带有标签的数据

学而时习之,不亦说乎! 373

SQLServer中操作XML数据

以下为学习记录,参照SQL Server 2008 联机丛书资料及其他书籍,以前知道sql中可以处理XML数据,但是没有了解得很肤浅,由于现在很多web站点提供API,但是返回的数据大都是XML格式的,解析也主要是用C#解析的! 但是我想如果把xml放在数据用sql来解析,在生成表是不是更好呢?(说实话,实际项目中还没有用XML字段呢!)先学习记录! USE Northwind GO /...

weixin_30673715的博客 109

sql server xml二

declare @xml xml select @xml=' chinajiabing 男 20 jiabing 男 23 ' --1.query 获得第二名同学的年龄元素 select @xml.query('class/student[@id=2]/age[1]') --2.value 获得第二名同学的年龄只含内容 select @xml.value

ChinaJiaBing的专栏 473

SQL Server XML基础学习之<5>—XQuery(query)

T-SQL 支持用于查询 XML 数据类型的 XQuery 语言的子集。 XQuery 基于现有的 XPath 查询语言,并支持更好的迭代、更好的排序结果以及构造必需的 XML 的功能。 在前面我们已经学习了 XPath 的基本语法,本章将学习T-SQL 的 XQuery 语法 -----------------------------------------------------------...

Backcanhave7 1921

sql 查询xml数据_使用SQL查询DB2 XML数据

尽管DB2的混合体系结构与以前的版本相比有很大的不同,但是利用其新的XML功能并不一定是一个痛苦的过程。 如果您已经熟悉SQL,则可以立即将您的技能应用于处理本机存储在DB2中的XML数据。 参见本文内容。 DB2 9中的XML功能包括新的存储管理,索引和查询语言支持。 在本文中,学习如何使用SQL或带有XML扩展SQL(SQL / XML)查询DB2 XML列中的数据。 该系列的下一篇文...

cuyi7076的博客 2817

sql 2005 更新xml

1.insertinsert用于将Expression1标识的一个或多个节点作为Expression2标识的节点的子节点或同级节点插入。语法格式如下:insertExpression1 ({as first | as last} into | after | beforeExpression2)Expression1和Expression2 标识要插入的一个或多个节

ちえをだそう―さざなみ 1170

转载--SQL Server 2005的XQuery介绍

原文地址: http://bbs.51cto.com/thread-458009-1-1.html 引用: 摘要 本文介绍了SQL Server 2005能够支持的XQuery的各方面特性如FLWOR语句,XQuery的操作,if-then-else结构,XML的构造函数,XQuery的内置函数,类型的转换操作符,并举例说明了上述XQuery功能的应用和操作。本文同时也对S...

dianxunma2886的博客 239

XQuery 添加元素和属性

XQuery(XML Query)是一种用于查询 XML 数据的语言,它是由 W3C 制定的标准。XQuery 的语法类似于 SQL,但它专门用于处理 XML 数据。XQuery 可以用于查询、更新、转换和生成 XML 数据。在本文中,我们探讨了如何在 XQuery 中添加元素和属性,以及如何使用 XQuery 更新 XML 文档。我们学习了如何使用insert表达式来添加新的元素,如何使用attribute函数来添加新的属性,以及如何使用rename和delete表达式来更新和删除元素和属性。

wjs2024的博客 329
上一篇: 了解SQL Server数据库恢复模型
下一篇: sql server新增列_SQL Server 2016安装中的新增功能?
culuo4781
博客等级 码龄11年 312粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值