SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

SQL server graph database

By Jayendra Viswanathan,

SQL Server has a feature to implement many-to-many relationships model. SQL server graph database capabilities is available in SQL Server 2017. Let us see the codes to implement the same.
We shall create the base table as “Org”. Load data into the table with the Insert command. We shall create “OrgNode” table as Node. The data from Base table “Org” will be loaded with Node details into the “OrgNode” Node table. 
“OrgEdge” is the table that stores the relationship data between the rows in the Base table “Org”. Edge table contains the From and To of Node table “OrgEdge”. Once the data is ready in he “OrgEdge” table, we will use MATCH clause to retrieve the data.  In the example, George is the first level employee, he has 1 employee who reports to him which is Peter. Peter has two resources who reports to him they  Jeff and Tedd. The last query in the above code sample will get the employees reporting to the Peter, they are Jeff and Ted.

Total article views: 399 | Views in the last 30 days: 6
Related Articles

Custom Dll Report Server

Report Server


Selecting from hierarchies like Managers and Employees

Chuck Hoffman shows a technique using sets for selecting records from hierarchies such as Manager / ...


Employee Retention

A SQL Server DBA seems to be a stable job and many of us stick with the same job for an above averag...


Advice - Table design for Employee Reporting Hierarchy

Tables for historical reporting hierarchy


Employee Slurping

This editorial was originally published on Oct 21, 2006. It is being re-run as Steve is out at SQL i...