%META:TOPICPARENT{name="VirtTipsAndTricksSPARQL11FeaturesExamplesCollection"}% ---+Virtuoso SPARQL 1.1. DELETE Usage Examples %TOC% ---++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. %BR%%BR%Note: There should be either DELETE WHERE OR DELETE DATA but not both DATA and WHERE in same sequence.%BR% ---++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> 1 Assume the following Raw Data Representation in Turtle: <#book2> 42 . <#book2> "David Copperfield" . <#book2> "Edmund Wells" . 1 Load the sample data: INSERT DATA { GRAPH { <#book2> 42 . <#book2> "David Copperfield" . <#book2> "Edmund Wells" . } } 1 Delete 2 triples from the graph: DELETE DATA FROM { <#book2> "David Copperfield" ; "Edmund Wells" . } 1 Query the graph data: SELECT * FROM WHERE { ?s ?p ?o } 1 [[http://bit.ly/VAfJGX][View the SPARQL Query Definition via SPARQL Protocol URL]]; 1 [[http://bit.ly/WGmFxa][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> : 1 Assume the following Raw Data Representation in Turtle: <#william> a . <#william> "William" . <#william> . <#fred> a . <#fred> "Fred" . <#fred> . 1 Load the sample data: INSERT DATA { GRAPH { <#william> a . <#william> "William" . <#william> . <#fred> a . <#fred> "Fred" . <#fred> . } } 1 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 DELETE { ?person ?property ?value } WHERE { ?person ?property ?value ; "Fred" } 1 Query the graph data: SELECT * FROM WHERE { ?s ?p ?o } 1 [[http://bit.ly/11qwNRq][View the SPARQL Query Definition via SPARQL Protocol URL]]; 1 [[http://bit.ly/WE3erM][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>). 1 Assume the following Raw Data Representation in Turtle: <#william> a . <#william> "William" . <#fred> a . <#fred> "Fred" . 1 Load the sample data: INSERT DATA { GRAPH { <#william> a . <#william> "William" . <#fred> a . <#fred> "Fred" . } } 1 Assume another Raw Data Representation in Turtle: <#william> . <#fred> . 1 Load the sample data: INSERT DATA { GRAPH { <#william> . <#fred> . } } 1 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 { ?person 'Fred' ; ?property1 ?value1 . } GRAPH { ?person ?property2 ?value2 . } } 1 Query the graph <urn:sparql:tests:delete:where1> data: SELECT * FROM WHERE { ?s ?p ?o } 1 [[http://bit.ly/VC4H0k][View the SPARQL Query Definition via SPARQL Protocol URL]]; 1 [[http://bit.ly/YpTukb][View the SPARQL Query Results via SPARQL Protocol URL]] 1 Query the graph <urn:sparql:tests:delete:where2> data: SELECT * FROM WHERE { ?s ?p ?o } 1 [[http://bit.ly/UL4qcl][View the SPARQL Query Definition via SPARQL Protocol URL]]; 1 [[http://bit.ly/WE3irG][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: 1 Assume the following Raw Data Representation in Turtle: <#william> a . <#william> "William" . <#william> . <#fred> a . <#fred> "Fred" . <#fred> . 1 Load the sample data: INSERT DATA { GRAPH { <#william> a . <#william> "William" . <#william> . <#fred> a . <#fred> "Fred" . <#fred> . } } 1 Remove all statements about anything with a given name of "Fred": WITH DELETE { ?person ?property ?value } WHERE { ?person ?property ?value ; 'Fred' } 1 Query the graph <urn:sparql:tests:delete:informative> data: SELECT * FROM WHERE { ?s ?p ?o } 1 [[http://bit.ly/W6XKV3][View the SPARQL Query Definition via SPARQL Protocol URL]]; 1 [[http://bit.ly/Vsq4zl][View the SPARQL Query Results via SPARQL Protocol URL]] ---++Related * [[http://www.w3.org/TR/2012/PR-sparql11-update-20121108/#deleteData][SPARQL 1.1 DELETE DATA]] * [[http://www.w3.org/TR/rdf-sparql-protocol/][SPARQL Protocol (HTTP based Query Service)]] * [[VirtTipsAndTricksGuide][Virtuoso Tips and Tricks Collection]] * [[VirtTipsAndTricksSPARQL11FeaturesExamplesCollection][Virtuoso SPARQL 1.1 Usage Examples Collection]] * [[http://virtuoso.openlinksw.com/tutorials/sparql/SPARQL_Tutorials_Part_9/SPARQL_Tutorials_Part_9.html][Virtuoso SPARQL 1.1 Syntax Tutorial]] * [[http://docs.openlinksw.com/virtuoso/rdfsparql.html][Virtuoso Documentation]]