VirtTipsAndTricksSPARQL11DeleteVirtuoso SPARQL 1.1. DELETE Usage ExamplesVirtuoso SPARQL 1.1. DELETE Usage Examples What? 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.Note: There should be either DELETE WHERE OR DELETE DATA but not both DATA and WHERE in same sequence. Why? Using DELETE to manage graphs data.How? Here are some examples showcasing Virtuoso's support for this functionality: DELETE DATA Examples Removing Triples from a Graph Example This example request describes 2 triples to be removed from the named graph identified by the IRI <urn:sparql:tests:delete:data> Assume the following Raw Data Representation in Turtle: <#book2> <http://example.org/ns#price> 42 . <#book2> <http://purl.org/dc/elements/1.1/title> "David Copperfield" . <#book2> <http://purl.org/dc/elements/1.1/creator> "Edmund Wells" . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:delete:data> { <#book2> <http://example.org/ns#price> 42 . <#book2> <http://purl.org/dc/elements/1.1/title> "David Copperfield" . <#book2> <http://purl.org/dc/elements/1.1/creator> "Edmund Wells" . } } Delete 2 triples from the graph: DELETE DATA FROM <urn:sparql:tests:delete:data> { <#book2> <http://purl.org/dc/elements/1.1/title> "David Copperfield" ; <http://purl.org/dc/elements/1.1/creator> "Edmund Wells" . } Query the graph data: SELECT * FROM <urn:sparql:tests:delete:data> WHERE { ?s ?p ?o } View the SPARQL Query Definition via SPARQL Protocol URL; View the SPARQL Query Results via SPARQL Protocol URL DELETE WHERE Examples Removing Triples from a Graph Example This example request removes all statements about anything with a given name of "Fred" from the named graph identified by the IRI <urn:sparql:tests:delete:where> : Assume the following Raw Data Representation in Turtle: <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#william> <http://xmlns.com/foaf/0.1/foaf/mbox> <mailto:bill@example> . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:delete:where> { <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#william> <http://xmlns.com/foaf/0.1/foaf/mbox> <mailto:bill@example> . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . } } Delete all statements about anything with a given name of "Fred" from the graph. A WITH clause is present, meaning that graph <urn:sparql:tests:delete:where> is both the one from which triples are being removed and the one which the WHERE clause is matched against: WITH <urn:sparql:tests:delete:where> DELETE { ?person ?property ?value } WHERE { ?person ?property ?value ; <http://xmlns.com/foaf/0.1/givenName> "Fred" } Query the graph data: SELECT * FROM <urn:sparql:tests:delete:where> WHERE { ?s ?p ?o } View the SPARQL Query Definition via SPARQL Protocol URL; View the SPARQL Query Results via SPARQL Protocol URL Removing Triples in 2 graphs that have corresponding triples Example This example request removes both statements naming some resource "Fred" in the graph <urn:sparql:tests:delete:where1> , and also statements about that resource from the graph <urn:sparql:tests:delete:where2> (assuming that some of the resources in the graph <urn:sparql:tests:delete:where1> have corresponding triples in the graph <urn:sparql:tests:delete:where2>). Assume the following Raw Data Representation in Turtle: <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:delete:where1> { <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . } } Assume another Raw Data Representation in Turtle: <#william> <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:delete:where2> { <#william> <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . } } Remove statements naming some resource "Fred" in the graph <urn:sparql:tests:delete:where1> , and also statements about that resource from the graph <urn:sparql:tests:delete:where2> : DELETE WHERE { GRAPH <urn:sparql:tests:delete:where1> { ?person <http://xmlns.com/foaf/0.1/givenName> 'Fred' ; ?property1 ?value1 . } GRAPH <urn:sparql:tests:delete:where2> { ?person ?property2 ?value2 . } } Query the graph <urn:sparql:tests:delete:where1> data: SELECT * FROM <urn:sparql:tests:delete:where1> WHERE { ?s ?p ?o } View the SPARQL Query Definition via SPARQL Protocol URL; View the SPARQL Query Results via SPARQL Protocol URL Query the graph <urn:sparql:tests:delete:where2> data: SELECT * FROM <urn:sparql:tests:delete:where2> WHERE { ?s ?p ?o } View the SPARQL Query Definition via SPARQL Protocol URL; View the SPARQL Query Results via SPARQL Protocol URL DELETE (Informative) Examples Remove Triples from graph about anything with given name "Fred" This example request removes all statements about anything with a given name of "Fred" from the graph <urn:sparql:tests:delete:informative> . A WITH clause is present, meaning that graph <urn:sparql:tests:delete:informative> is both the one from which triples are being removed and the one which the WHERE clause is matched against: Assume the following Raw Data Representation in Turtle: <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#william> <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . Load the sample data: INSERT DATA { GRAPH <urn:sparql:tests:delete:informative> { <#william> a <http://xmlns.com/foaf/0.1/Person> . <#william> <http://xmlns.com/foaf/0.1/givenName> "William" . <#william> <http://xmlns.com/foaf/0.1/mbox> <mailto:bill@example> . <#fred> a <http://xmlns.com/foaf/0.1/Person> . <#fred> <http://xmlns.com/foaf/0.1/givenName> "Fred" . <#fred> <http://xmlns.com/foaf/0.1/mbox> <mailto:fred@example> . } } Remove all statements about anything with a given name of "Fred": WITH <urn:sparql:tests:delete:informative> DELETE { ?person ?property ?value } WHERE { ?person ?property ?value ; <http://xmlns.com/foaf/0.1/givenName> 'Fred' } Query the graph <urn:sparql:tests:delete:informative> data: SELECT * FROM <urn:sparql:tests:delete:informative> WHERE { ?s ?p ?o } View the SPARQL Query Definition via SPARQL Protocol URL; View the SPARQL Query Results via SPARQL Protocol URL Related SPARQL 1.1 DELETE DATA SPARQL Protocol (HTTP based Query Service) Virtuoso Tips and Tricks Collection Virtuoso SPARQL 1.1 Usage Examples Collection Virtuoso SPARQL 1.1 Syntax Tutorial Virtuoso Documentation