<docbook><section><title>VirtTipsAndTricksSPARQL11Delete</title><title>Virtuoso SPARQL 1.1.
 DELETE Usage Examples</title>Virtuoso SPARQL 1.1.
 DELETE Usage Examples
<bridgehead class="http://www.w3.org/1999/xhtml:h2">What?</bridgehead>
 This guide contains Virtuoso SPARQL 1.1.
 DELETE Usage examples queries which you can run against any SPARQL endpoint that supports SPARQL 1.1 and the ability to allow a verified user perform INSERT/DELETE operations.<emphasis>Note</emphasis>: There should be either DELETE WHERE OR DELETE DATA but not both DATA and WHERE in same sequence.<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2">Why?</bridgehead>
 Using DELETE to manage graphs data.<bridgehead class="http://www.w3.org/1999/xhtml:h2">How?</bridgehead>
<para>Here are some examples showcasing Virtuoso&#39;s support for this functionality:</para>
<para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">DELETE DATA Examples</bridgehead>
<bridgehead class="http://www.w3.org/1999/xhtml:h4">Removing Triples from a Graph Example</bridgehead>
<para>This example request describes 2 triples to be removed from the named graph identified by the IRI &lt;urn:sparql:tests:delete:data&gt;</para>
<orderedlist spacing="compact"><listitem>Assume the following Raw Data Representation in Turtle: <programlisting>&lt;#book2&gt; &lt;http://example.org/ns#price&gt; 42 .
&lt;#book2&gt; &lt;http://purl.org/dc/elements/1.1/title&gt; &quot;David Copperfield&quot; .
&lt;#book2&gt; &lt;http://purl.org/dc/elements/1.1/creator&gt; &quot;Edmund Wells&quot; .
</programlisting></listitem>
<listitem>Load the sample data: <programlisting>INSERT DATA
  { 
    GRAPH &lt;urn:sparql:tests:delete:data&gt; 
      { 
        &lt;#book2&gt; &lt;http://example.org/ns#price&gt; 42 .
        &lt;#book2&gt; &lt;http://purl.org/dc/elements/1.1/title&gt; &quot;David Copperfield&quot; .
        &lt;#book2&gt; &lt;http://purl.org/dc/elements/1.1/creator&gt; &quot;Edmund Wells&quot; .
      } 
  }
</programlisting></listitem>
<listitem>Delete 2 triples from the graph: <programlisting>DELETE DATA FROM &lt;urn:sparql:tests:delete:data&gt; 
  {
    &lt;#book2&gt; &lt;http://purl.org/dc/elements/1.1/title&gt;   &quot;David Copperfield&quot; ; 
             &lt;http://purl.org/dc/elements/1.1/creator&gt; &quot;Edmund Wells&quot;      .
  }
</programlisting></listitem>
<listitem>Query the graph data: <programlisting>SELECT * 
FROM &lt;urn:sparql:tests:delete:data&gt; 
WHERE 
  {
    ?s ?p ?o
  }
</programlisting></listitem>
<listitem><ulink url="http://bit.ly/VAfJGX">View the SPARQL Query Definition via SPARQL Protocol URL</ulink>; </listitem>
<listitem><ulink url="http://bit.ly/WGmFxa">View the SPARQL Query Results via SPARQL Protocol URL</ulink></listitem>
</orderedlist><para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">DELETE WHERE Examples</bridgehead>
<bridgehead class="http://www.w3.org/1999/xhtml:h4">Removing Triples from a Graph Example</bridgehead>
<para>This example request removes all statements about anything with a given name of &quot;Fred&quot; from the named graph identified by the IRI &lt;urn:sparql:tests:delete:where&gt; : </para>
<orderedlist spacing="compact"><listitem>Assume the following Raw Data Representation in Turtle: <programlisting>&lt;#william&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; .
&lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;William&quot; .
&lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/foaf/mbox&gt; &lt;mailto:bill@example&gt; .

&lt;#fred&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; .
&lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;Fred&quot; .
&lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/mbox&gt; &lt;mailto:fred@example&gt; .

</programlisting></listitem>
<listitem>Load the sample data: <programlisting>INSERT DATA
  { 
    GRAPH &lt;urn:sparql:tests:delete:where&gt; 
      { 
        &lt;#william&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; .
        &lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;William&quot; .
        &lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/foaf/mbox&gt; &lt;mailto:bill@example&gt; .

        &lt;#fred&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; .
        &lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;Fred&quot; .
        &lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/mbox&gt; &lt;mailto:fred@example&gt; .
      } 
  }
</programlisting></listitem>
<listitem>Delete all statements about anything with a given name of &quot;Fred&quot; from the graph.
 A WITH clause is present, meaning that graph &lt;urn:sparql:tests:delete:where&gt; is both the one from which triples are being removed and the one which the WHERE clause is matched against: <programlisting>WITH &lt;urn:sparql:tests:delete:where&gt;
DELETE { ?person ?property ?value } 
WHERE 
  { ?person ?property ?value ; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;Fred&quot; } 
</programlisting></listitem>
<listitem>Query the graph data: <programlisting>SELECT * 
FROM &lt;urn:sparql:tests:delete:where&gt; 
WHERE 
  {
    ?s ?p ?o
  }
</programlisting></listitem>
<listitem><ulink url="http://bit.ly/11qwNRq">View the SPARQL Query Definition via SPARQL Protocol URL</ulink>; </listitem>
<listitem><ulink url="http://bit.ly/WE3erM">View the SPARQL Query Results via SPARQL Protocol URL</ulink></listitem>
</orderedlist><bridgehead class="http://www.w3.org/1999/xhtml:h4">Removing Triples in 2 graphs that have corresponding triples Example</bridgehead>
<para>This example request removes both statements naming some resource &quot;Fred&quot; in the graph &lt;urn:sparql:tests:delete:where1&gt; , and also statements about that resource from the graph &lt;urn:sparql:tests:delete:where2&gt; (assuming that some of the resources in the graph &lt;urn:sparql:tests:delete:where1&gt; have corresponding triples in the graph &lt;urn:sparql:tests:delete:where2&gt;).</para>
<orderedlist spacing="compact"><listitem>Assume the following Raw Data Representation in Turtle: <programlisting>&lt;#william&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; .
&lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;William&quot; .

&lt;#fred&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; .
&lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;Fred&quot; .
</programlisting></listitem>
<listitem>Load the sample data: <programlisting>INSERT DATA
  { 
    GRAPH &lt;urn:sparql:tests:delete:where1&gt; 
      { 
        &lt;#william&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; . 
        &lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;William&quot; . 
 
        &lt;#fred&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; . 
        &lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;Fred&quot; . 
      } 
  }
</programlisting></listitem>
<listitem>Assume another Raw Data Representation in Turtle: <programlisting>&lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/mbox&gt;  &lt;mailto:bill@example&gt; .
&lt;#fred&gt;    &lt;http://xmlns.com/foaf/0.1/mbox&gt;  &lt;mailto:fred@example&gt; .
</programlisting></listitem>
<listitem>Load the sample data: <programlisting>INSERT DATA
  { 
    GRAPH &lt;urn:sparql:tests:delete:where2&gt; 
      { 
        &lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/mbox&gt;  &lt;mailto:bill@example&gt; .
        &lt;#fred&gt;    &lt;http://xmlns.com/foaf/0.1/mbox&gt;  &lt;mailto:fred@example&gt; .
      } 
  }
</programlisting></listitem>
<listitem>Remove statements naming some resource &quot;Fred&quot; in the graph &lt;urn:sparql:tests:delete:where1&gt; , and also statements about that resource from the graph &lt;urn:sparql:tests:delete:where2&gt; : <programlisting>DELETE WHERE 
  {
    GRAPH &lt;urn:sparql:tests:delete:where1&gt; 
      {
        ?person &lt;http://xmlns.com/foaf/0.1/givenName&gt; &#39;Fred&#39;  ; 
                                           ?property1 ?value1 . 
      }
    GRAPH &lt;urn:sparql:tests:delete:where2&gt; 
      {
        ?person ?property2 ?value2 . 
      }
  }
</programlisting></listitem>
<listitem>Query the graph &lt;urn:sparql:tests:delete:where1&gt; data: <programlisting>SELECT * 
FROM &lt;urn:sparql:tests:delete:where1&gt; 
WHERE 
  {
    ?s ?p ?o
  }
</programlisting></listitem>
<listitem><ulink url="http://bit.ly/VC4H0k">View the SPARQL Query Definition via SPARQL Protocol URL</ulink>; </listitem>
<listitem><ulink url="http://bit.ly/YpTukb">View the SPARQL Query Results via SPARQL Protocol URL</ulink> </listitem>
<listitem>Query the graph &lt;urn:sparql:tests:delete:where2&gt; data: <programlisting>SELECT * 
FROM &lt;urn:sparql:tests:delete:where2&gt; 
WHERE 
  {
    ?s ?p ?o
  }
</programlisting></listitem>
<listitem><ulink url="http://bit.ly/UL4qcl">View the SPARQL Query Definition via SPARQL Protocol URL</ulink>; </listitem>
<listitem><ulink url="http://bit.ly/WE3irG">View the SPARQL Query Results via SPARQL Protocol URL</ulink></listitem>
</orderedlist><bridgehead class="http://www.w3.org/1999/xhtml:h3">DELETE (Informative) Examples</bridgehead>
<bridgehead class="http://www.w3.org/1999/xhtml:h4">Remove Triples from graph about anything with given name &quot;Fred&quot;</bridgehead>
<para> This example request removes all statements about anything with a given name of &quot;Fred&quot; from the graph &lt;urn:sparql:tests:delete:informative&gt; . A WITH clause is present, meaning that graph &lt;urn:sparql:tests:delete:informative&gt;  is both the one from which triples are being removed and the one which the WHERE clause is matched against:</para>
<para> </para>
<orderedlist spacing="compact"><listitem>Assume the following Raw Data Representation in Turtle: <programlisting>&lt;#william&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; . 
&lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;William&quot; . 
&lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/mbox&gt; &lt;mailto:bill@example&gt; . 

&lt;#fred&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; . 
&lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;Fred&quot; . 
&lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/mbox&gt; &lt;mailto:fred@example&gt; . 
</programlisting></listitem>
<listitem>Load the sample data: <programlisting>INSERT DATA
  { 
    GRAPH &lt;urn:sparql:tests:delete:informative&gt; 
      { 
        &lt;#william&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; . 
        &lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;William&quot; . 
        &lt;#william&gt; &lt;http://xmlns.com/foaf/0.1/mbox&gt; &lt;mailto:bill@example&gt; . 

        &lt;#fred&gt; a &lt;http://xmlns.com/foaf/0.1/Person&gt; . 
        &lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &quot;Fred&quot; . 
        &lt;#fred&gt; &lt;http://xmlns.com/foaf/0.1/mbox&gt; &lt;mailto:fred@example&gt; . 
      } 
  }
</programlisting></listitem>
<listitem>Remove all statements about anything with a given name of &quot;Fred&quot;: <programlisting>WITH &lt;urn:sparql:tests:delete:informative&gt;
DELETE { ?person ?property ?value } 
WHERE { ?person ?property ?value ; &lt;http://xmlns.com/foaf/0.1/givenName&gt; &#39;Fred&#39; } 
</programlisting></listitem>
<listitem>Query the graph &lt;urn:sparql:tests:delete:informative&gt; data: <programlisting>SELECT * 
FROM &lt;urn:sparql:tests:delete:informative&gt; 
WHERE 
  {
    ?s ?p ?o
  }
</programlisting></listitem>
<listitem><ulink url="http://bit.ly/W6XKV3">View the SPARQL Query Definition via SPARQL Protocol URL</ulink>; </listitem>
<listitem><ulink url="http://bit.ly/Vsq4zl">View the SPARQL Query Results via SPARQL Protocol URL</ulink></listitem>
</orderedlist><bridgehead class="http://www.w3.org/1999/xhtml:h2">Related</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="http://www.w3.org/TR/2012/PR-sparql11-update-20121108/#deleteData">SPARQL 1.1 DELETE DATA</ulink> </listitem>
<listitem><ulink url="http://www.w3.org/TR/rdf-sparql-protocol/">SPARQL Protocol (HTTP based Query Service)</ulink> </listitem>
<listitem><ulink url="VirtTipsAndTricksGuide">Virtuoso Tips and Tricks Collection</ulink> </listitem>
<listitem><ulink url="VirtTipsAndTricksSPARQL11FeaturesExamplesCollection">Virtuoso SPARQL 1.1 Usage Examples Collection</ulink> </listitem>
<listitem><ulink url="http://virtuoso.openlinksw.com/tutorials/sparql/SPARQL_Tutorials_Part_9/SPARQL_Tutorials_Part_9.html">Virtuoso SPARQL 1.1 Syntax Tutorial</ulink> </listitem>
<listitem><ulink url="http://docs.openlinksw.com/virtuoso/rdfsparql.html">Virtuoso Documentation</ulink> </listitem>
</itemizedlist></section></docbook>