Summary: * Prefix filenames with order in which they should appear in the sidebar. * Fix links Reviewers: buda Reviewed By: buda Differential Revision: https://phabricator.memgraph.io/D1618
2.5 KiB
Writing New Data
For adding new data, you can use the following clauses.
CREATE
, for creating new nodes and edges.SET
, for adding new or updating existing labels and properties.DELETE
, for deleting nodes and edges.REMOVE
, for removing labels and properties.
You can still use the RETURN
clause to produce results after writing, but it
is not mandatory.
Details on which kind of data can be stored in Memgraph can be found in Data Storage chapter.
CREATE
This clause is used to add new nodes and edges to the database. The creation
is done by providing a pattern, similarly to MATCH
clause.
For example, to create 2 new nodes connected with a new edge, use this query.
CREATE (node1)-[:edge_type]->(node2)
Labels and properties can be set during creation using the same syntax as in
MATCH
patterns. For example, creating a node with a label and a
property:
CREATE (node :Label {property: "my property value"})
Additional information on CREATE
is
here.
SET
The SET
clause is used to update labels and properties of already existing
data.
Example. Incrementing everyone's age by 1.
MATCH (n :Person) SET n.age = n.age + 1
Click
here
for a more detailed explanation on what can be done with SET
.
DELETE
This clause is used to delete nodes and edges from the database.
Example. Removing all edges of a single type.
MATCH ()-[edge :type]-() DELETE edge
When testing the database, you want to often have a clean start by deleting every node and edge in the database. It is reasonable that deleting each node should delete all edges coming into or out of that node.
MATCH (node) DELETE node
But, openCypher prevents accidental deletion of edges. Therefore, the above
query will report an error. Instead, you need to use the DETACH
keyword,
which will remove edges from a node you are deleting. The following should
work and delete everything in the database.
MATCH (node) DETACH DELETE node
More examples are here.
REMOVE
The REMOVE
clause is used to remove labels and properties from nodes and
edges.
Example.
MATCH (n :WrongLabel) REMOVE n :WrongLabel, n.property