Neo 4 J
Neo 4 J
Sr.N
RDBMS Graph Database
o
1 Tables Graphs
2 Rows Nodes
3 Columns and Data Properties and its values
4 Constraints Relationships
5 Joins Traversal
Advantages of Neo4j
• Node Name =
"Employee" and it
contains a set of
properties as key-value
pairs.
Properties
• Key = Value
• CREATE (sample)
• Verification
• To verify the creation of the node type, execute the
following query in the dollar prompt.
• MATCH (n) RETURN n
Creating Multiple Nodes
• CREATE (node1),(node2)
• Ex . CREATE (sample1),(sample2)
• Verification
• To verify the creation of the node, type and
execute the following query in the dollar
prompt.
• MATCH (n) RETURN n This query returns all
the nodes in the database
Creating a Node with a Label
Ex - CREATE (Dhawan:person:player)
Create Node with Properties
• Syntax
CREATE (node:label { key1: value, key2: value, . . . .
. . . . . })
• Ex.
• MERGE (Jadeja:player {name: "Ravindra
Jadeja", YOB: 1988, POB: "NavagamGhed"})
RETURN Jadeja
OnCreate and OnMatch
• CREATE (node1)-[:RelationshipType]-
>(node2)
Ex
• CREATE (Raul:player{name: "Raul Vinci", YOB:
1973, POB: "Milan"})
• CREATE (It:Country {name: "Itly"})
• RETURN Raul, It
• -------------------------------------------------------
• CREATE (Raul)-[r:PLAYER_OF]->(It)
• RETURN Raul, It
Create a Relationship between existing Nodes
• Syntax:
• MATCH (a:LabeofNode1), (b:LabeofNode2)
• WHERE a.name = "nameofnode1" AND b.nam
e = " nameofnode2"
• CREATE (a)-[: Relation]->(b)
• RETURN a,b
Create a relationship using MATCH statement.
• Syntax:
• CREATE (node1)-
[label:Rel_Type {key1:value1, key2:value2, . . .
n}]-> (node2)
First create a node "Kohli", having multiple labels
• CREATE (Kohli:person:player)
• Syntax:
• CREATE p = (Node1 {properties})-
[:Relationship_Type]->
• (Node2 {properties})[:Relationship_Type]-
>(Node3 {properties})
• RETURN p
First create a node3 name
"Champions_Trophy" to do further operations.
• Query
• MATCH (n) DETACH DELETE n
Deleting a Particular Node
• Syntax