Deletion of rows with XML documents from tables
To delete rows that contain XML documents, you can use the DELETE SQL statement. You can include a WHERE clause when you want to delete specific rows.
You can specify which rows are to be deleted based on values within XML columns. To find values within XML documents, you need to use XQuery expressions. One way of specifying XQuery expressions is with the XMLEXISTS predicate. When you specify XMLEXISTS in a WHERE clause, rows are deleted if the XQuery expression returns a non-empty sequence.
If an XML column is nullable, to delete a value from the XML column without deleting the row, use the UPDATE SQL statement to set the column value to NULL.
The following examples demonstrate how XML data can be deleted from XML columns. The examples use table MYCUSTOMER, which is a copy of the sample CUSTOMER table, and assume that MYCUSTOMER has been populated with all of the Customer data.
DELETE FROM MYCUSTOMER WHERE CID=1002
city
element is Markham
. DELETE FROM MYCUSTOMER
WHERE XMLEXISTS ('declare default element namespace "http://posample.org";
//addr[city="Markham"]' passing INFO)
city
element
is Markham
, but leave the row. UPDATE MYCUSTOMER SET INFO = NULL
WHERE XMLEXISTS ('$declare default element namespace "http://posample.org";
//addr[city="Markham"]' passing INFO)