SPARQL 1.1 Update provides these graph update operations ( See more from the specification ):
Here are some examples showcasing Virtuoso's support for this functionality:
This example demonstrates two operations -- delete a triple and add a triple in the named graph identified by the IRI <urn:sparql:tests:update> :
<#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Desing" .
INSERT DATA { GRAPH <urn:sparql:tests:update> { <#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" . } }
DELETE DATA { GRAPH <urn:sparql:tests:update> { <#book1> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" } }
INSERT DATA { GRAPH <urn:sparql:tests:update> { <#book2> <http://purl.org/dc/elements/1.1/title> "Fundamentals of Compiler Design" } }
SELECT * FROM <urn:sparql:tests:update> WHERE { ?s ?p ?o }
This example demonstrates how to rename all people with the given name "Bill" to "William":
<#president25> <http://xmlns.com/foaf/0.1/givenName> "Bill" . <#president25> <http://xmlns.com/foaf/0.1/foaf:familyName> "McKinley" . <#president27> <http://xmlns.com/foaf/0.1/foaf:givenName> "Bill" . <#president27> <http://xmlns.com/foaf/0.1/foaf:familyName> "Taft" . <#president42> <http://xmlns.com/foaf/0.1/foaf:givenName> "Bill" . <#president42> <http://xmlns.com/foaf/0.1/foaf:familyName> "Clinton" .
INSERT DATA { GRAPH <urn:sparql:tests:update:insert:delete:with> { <#president25> <http://xmlns.com/foaf/0.1/givenName> "Bill" . <#president25> <http://xmlns.com/foaf/0.1/foaf:familyName> "McKinley" . <#president27> <http://xmlns.com/foaf/0.1/foaf:givenName> "Bill" . <#president27> <http://xmlns.com/foaf/0.1/foaf:familyName> "Taft" . <#president42> <http://xmlns.com/foaf/0.1/foaf:givenName> "Bill" . <#president42> <http://xmlns.com/foaf/0.1/foaf:familyName> "Clinton" . } }
WITH <urn:sparql:tests:update:insert:delete:with> DELETE { ?person <http://xmlns.com/foaf/0.1/givenName> 'Bill' } INSERT { ?person <http://xmlns.com/foaf/0.1/givenName> 'William' } WHERE { ?person <http://xmlns.com/foaf/0.1/givenName> 'Bill' }
SELECT * FROM <urn:sparql:tests:update:insert:delete:with> WHERE { ?s ?p ?o }
This example demonstrates use of MODIFY to alter the objects of a schema:WebPage?
relation using objects of a foaf:homePage
relation.
In this example, we have a constant relation subject identified the HTTP URI <http://example.com/product/Sample1#this> .
<http://example.com/product/Sample1#this> <http://schema.org/WebPage> <http://sample1.com/index1> . <http://example.com/product/Sample2#this> <http://schema.org/WebPage> <http://sample2.com/index2> . <http://example.com/product/Sample3#this> <http://schema.org/WebPage> <http://sample3.com/index3> . <http://example.com/product/Sample4#this> <http://schema.org/WebPage> <http://sample4.com/index4> . <http://example.com/product/Sample5#this> <http://schema.org/WebPage> <http://sample5.com/index5> .
INSERT DATA { GRAPH <urn:sparql:tests:update:insert:delete:modify:graph1> { <http://example.com/product/Sample1#this> <http://schema.org/WebPage> <http://sample1.com/index1> . <http://example.com/product/Sample2#this> <http://schema.org/WebPage> <http://sample2.com/index2> . <http://example.com/product/Sample3#this> <http://schema.org/WebPage> <http://sample3.com/index3> . <http://example.com/product/Sample4#this> <http://schema.org/WebPage> <http://sample4.com/index4> . <http://example.com/product/Sample5#this> <http://schema.org/WebPage> <http://sample5.com/index5> . } }
<http://sample1.com/index1> <http://xmlns.com/foaf/0.1/homepage> <http://sample1.com/> . <http://sample2.com/index2> <http://xmlns.com/foaf/0.1/homepage> <http://sample2.com/> . <http://sample3.com/index3> <http://xmlns.com/foaf/0.1/homepage> <http://sample3.com/> . <http://sample4.com/index4> <http://xmlns.com/foaf/0.1/homepage> <http://sample4.com/> . <http://sample5.com/index5> <http://xmlns.com/foaf/0.1/homepage> <http://sample5.com/> .
INSERT DATA { GRAPH <urn:sparql:tests:update:insert:delete:modify:graph2> { <http://sample1.com/index1> <http://xmlns.com/foaf/0.1/homepage> <http://sample1.com/> . <http://sample2.com/index2> <http://xmlns.com/foaf/0.1/homepage> <http://sample2.com/> . <http://sample3.com/index3> <http://xmlns.com/foaf/0.1/homepage> <http://sample3.com/> . <http://sample4.com/index4> <http://xmlns.com/foaf/0.1/homepage> <http://sample4.com/> . <http://sample5.com/index5> <http://xmlns.com/foaf/0.1/homepage> <http://sample5.com/> . } }
PREFIX schema: <http://schema.org/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> MODIFY <urn:sparql:tests:update:insert:delete:modify:graph1> DELETE { <http://example.com/product/Sample1#this> schema:WebPage ?s . } INSERT { <http://example.com/product/Sample1#this> schema:WebPage ?ns . } WHERE { GRAPH <urn:sparql:tests:update:insert:delete:modify:graph1> { <http://example.com/product/Sample1#this> schema:WebPage ?s . } GRAPH <urn:sparql:tests:update:insert:delete:modify:graph2> { ?s foaf:homepage ?ns . } }
SELECT * FROM <urn:sparql:tests:update:insert:delete:modify:graph1> WHERE { ?s ?p ?o . FILTER (?s = <http://example.com/product/Sample1#this>) . }