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中非常棘手,意义重大。

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

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

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 = ?

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删除

xquery删除_XQuery实例删除SQL XML文档相关推荐

  1. python xml实例_python解析xml文档实例

    博客已迁移  新地址 打开 ======================= 今天恰好用到,记录一下 使用python 用到的包:xml.dom.minidom 需求: 有一个表,里面数据量比较大,每天 ...

  2. JavaEE之使用DOM4J和XPath对xml文档的添加,删除,查询操作

    程序运行结果如下图: XML文档如下: <?xml version="1.0" encoding="UTF-8"?><exam> < ...

  3. 对Xml文档进行操作(修改,删除)

    <?xml version="1.0" encoding="utf-8"?> <Products>   <Product id=& ...

  4. java jdom进行xml的增删改差_java使用DOM对XML文档进行增删改查操作实例代码

    本文研究的主要是java使用DOM对XML文档进行增删改查操作的相关代码,具体实例如下所示. 源代码: package com.zc.homeWork18; import java.io.File; ...

  5. ssis导入xml_使用SSIS包将XML文档导入SQL Server表

    ssis导入xml This article guides you through importing XML documents into SQL tables using SSIS package ...

  6. php循环获取xml节点,PHP_PHP遍历XML文档所有节点的方法,本文实例讲述了PHP遍历XML文档 - phpStudy...

    PHP遍历XML文档所有节点的方法 本文实例讲述了PHP遍历XML文档所有节点的方法.分享给大家供大家参考.具体实现方法如下: 1. contact.xml代码: J J J Manager Nati ...

  7. Visual C# 2008+SQL Server 2005 数据库与网络开发--9.2.1 XML文档

    XML全称为可扩展标记语言,它提供了一种描述结构化数据的方法.与主要用于控制数据的显示和外观的HTML标记不同,XML标记用于定义数据本身的结构和数据类型.XML使用一组标记来描绘数据元素.元素可能封 ...

  8. 怎么删除批注mysql_如何去掉 Word 文档修订和批注和不显示已删除内容

    你是否遇到过,打开文档的最终状态,而不是充满了删除线.下划线和边上的批注框,又或是格式错乱,总显示已删除的内容的文档,那么就需要去掉word文档的标记(含修订和批注). 注:为什么在"视图& ...

  9. Win10如何删除资源管理器中的图片/文档/音乐/视频等文件夹?

    Win10如何删除资源管理器中的图片/文档/音乐/视频等文件夹? 使用Win10系统的过程中,打开"此电脑",在资源管理器上面会有图片/文档/音乐/视频等6个文件夹,相信绝大数的用 ...

最新文章

  1. 心急如焚!程序员拥有 2.2 亿美元巨款,却想不起密码
  2. 自定义 ArrayList
  3. oracle的catalog,Oracle Rman Catalog的创建方法和备份原理
  4. 通过修改explorer.exe内存隐藏文件及注册表项
  5. springboot之设置mybatis打印sql输出
  6. 整数实例hdu2041(超级楼梯)
  7. Atitit 面试流程法 艾提拉总结 增加企业黑名单制度,出去前核对黑名单 免得白跑 增加白名单制度,统计分析号面试的企业,垃圾企业 中等分类 1.面试提前给指导人参考 具体分析企业性质 产
  8. 数字通信原理笔记(一)---概述
  9. guice android,android – 如何使用Guice的@Singleton?
  10. 重装服务器系统鼠标键盘用不了,win7重装系统后鼠标键盘不能用怎么办
  11. Oracle函数之listagg函数
  12. 10102 循环输入字符串
  13. Entrez Direct学习笔记
  14. 什么是数字化的马太效应
  15. 全景图像拼接(一)关于全景拼接论文推荐
  16. 微软面试题之数字谜题
  17. 堆(heap)系列_0x0A:3种方法一次性解决堆溢出问题
  18. 将平板电脑作为电脑显示器_平板电脑与智能显示器的比较
  19. oracle数据库启动报错ora-27102
  20. 基于jQuery的TreeGrid组件

热门文章

  1. go interface类型转换_Go语言的九大核心特性主要有哪些?
  2. 抽象工厂模式java_抽象工厂模式
  3. 底部显示水平滚动_LG专利展示带有可滚动显示屏和触控笔的智能手机
  4. head first设计模式 pdf_设计模式之观察者模式
  5. bzoj 2843: 极地旅行社
  6. js获取浏览器版本或者类别
  7. acdream 1042: Classification of the species 抽象无根树并查集
  8. [导入]给老家新楼的对联
  9. ASP.NET MVC+LINQ开发一个图书销售站点(6):创建数据层
  10. 【零基础学Java】—List集合(三十九)