SQL Server 2017 Graph Database an Overview

A graph database is a collection of nodes (or vertices) and edges (or relationships).
A node represents an entity (for example, a person or an organization) and an edge represents a relationship between the two nodes that it connects (for example, likes or friends). 
Both nodes and edges may have properties associated with them.


Main features:

  • A single edge can flexibly connect multiple nodes in a Graph Database
  • We can express pattern matching and multi-hop navigation queries easily


When to use a graph database?: 

  • When we have Hierarchical data
  • When we have Complex many to many relationships


We can achieve similar behavior using Relational database also.

Other vendors providing graph database functionality:

  • Neo4j
  • mongoDB
  • Oracle etc. 


Where is it used?

  • Recommendations on online shopping sites
  • Social networking sites to find your first or second connection
  • Portfolio analysis


What are the components of graph database?

  • Node - Consists of properties
    It creates $node_Id columns to uniquely identify each row
  • Edge - Connects two or more edge, it may or may not have properties
    It creates following columns:

    $edge_Id - to uniquely identify edge
    $from_Id - Unique Id of node
    $to_Id - Unique Id of node 

Example:

Problem scenario: Find organization hierarchy of a person



Using recursive CTE:


And perform pivot operation to get data on columns 

Using graph database:


Power Bi visualization of graph using Force-Directed Graph: 




No comments:

Powered by Blogger.