0% found this document useful (0 votes)
14 views4 pages

Graph Databases and Neo4j

A graph database, such as Neo4j, organizes data as nodes, relationships, and properties, allowing for flexible representation of entities and their connections. Unlike relational databases, which use predefined structures, graph databases store relationships at the record level, enabling efficient navigation and querying. The document also provides examples of querying relationships and properties, as well as creating and deleting nodes and relationships.

Uploaded by

Naqash Ashraf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Graph Databases and Neo4j

A graph database, such as Neo4j, organizes data as nodes, relationships, and properties, allowing for flexible representation of entities and their connections. Unlike relational databases, which use predefined structures, graph databases store relationships at the record level, enabling efficient navigation and querying. The document also provides examples of querying relationships and properties, as well as creating and deleting nodes and relationships.

Uploaded by

Naqash Ashraf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

What is Graph Database?

A graph database stores nodes and relationships instead of tables, or documents.

In Neo4j, information is organized as nodes, relationships, and properties.


Building blocks of the property graph model
Nodes are the entities in the graph.
 Nodes can be tagged with labels, representing their different roles in your domain.
(For example, Person).
 Nodes can hold any number of key-value pairs, or properties. (For example, name)
 Node labels may also attach metadata (such as index or constraint information) to
certain nodes.
Relationships provide directed, named, connections between two node entities
(e.g. Person LOVES Person).
 Relationships always have a direction, a type, a start node, and an end node, and
they can have properties, just like nodes.
 Nodes can have any number or type of relationships without sacrificing
performance.
 Although relationships are always directed, they can be navigated efficiently in any
direction.
If you’d like to learn more about any of these, you can read more about Graph
Data Modeling.

In Neo4j, information is organized as nodes, relationships, and properties.


Building blocks of the property graph model

Nodes are the entities in the graph.


 Nodes can be tagged with labels, representing their different roles in your domain.
(For example, Person).
 Nodes can hold any number of key-value pairs, or properties. (For example, name)
 Node labels may also attach metadata (such as index or constraint information) to
certain nodes.
Relationships provide directed, named, connections between two node entities
(e.g. Person LOVES Person).
 Relationships always have a direction, a type, a start node, and an end node, and
they can have properties, just like nodes.
 Nodes can have any number or type of relationships without sacrificing
performance.
 Although relationships are always directed, they can be navigated efficiently in any
direction.
How Does a Graph Database Differ from a Relational Database?
The main difference is the way relationships between entities
are stored. In a graph database, relationships are stored at the
individual record level, while a relational database uses
predefined structures, a.k.a. table definitions.

Query:

Query on the basis of realtionship

MATCH (player:Player) -[:PLAYS_FAR] →(team:Team)

WHERE team.name=’LA LAKERS’ OR team.name=’another’


RETURN player

(PLAYS_FOR is here relationship between node player and


teams and relationship has also properties)

Query on the basis of relationship property salary

MATCH (player:Player) -[contract:PLAYS_FOR] →[team:Team]

WHERE contract.salary >3500000

RETURN player,team
we want to find the salary of teammate of a player ali

MATCH (ali:Player {name:’ali’}) -


[:teammates]→[teammate:Team]

MATCH (teammate) -[contract:PLAYS_FOR] → (team:TEAM)

Where contract.salary >400000

return teammate

AGGREGATING:

MATCH (player:Player) -[gamePlayed:PLAYED_AGAINST] →

(team :Team)

return player.name, COUNT(gamePLayed)

TO DELETE A NODE: (we have to delete relationships first)

MATCH (n {name :’ali’}) DETACH DELETE n

TO DELETE ONLY ONE RELATIONSHIP

MATCH (n {name:’naqash’}) -[rel:PLAYS_FOR] → (:TEAM)


DELETE rel

now to create a node:

CREATE (:PLAYER{name:'Babar',age:26}) -[:PLAYS_FOR


{salaray:340000}] -> (:TEAM {name :'Kings'})

You might also like