Thursday , June 8 2023

SQL Server 2017 GraphDB

What is GraphDB?

GraphDB introduced in SQL Server 2017. We will examine GraphDB with examples in this article. At the end of the article, we will learn the architecture of GraphDB and how to query. In our article, we will also design a Normal table to address the difference between Relational DB and GraphDB.

GraphDB consists of Node and Edge tables. A Node represents an entity. This can be a person or organization. An Edge indicates the relationship between the two nodes to which it is connected. You can create Node and Edge tables under any Schema in the database, but they all belong to a logical graph.


SQL Server Relational Database Example

In this example, we will see how the relational database query works and create three tables for it.

Our Tables: Personel, WorksIn ve Company

After creating these tables, we will insert our demo data into our tables and prepare related queries.

Let’s create our Demo database.

Create Database

Create Demo Tables

Insert Records into Tables

Insert data into created tables.

You can see the columns we relate the tables in the graph below.

As you can see, we can access the WorksIn table by using Personel_id in the Personel table by matching it with Personel_id in WorksIn.

Then we can access the Company table by using Cmp_Id in WorksIn table by matching it with the cmp_ID in Company table.

The query should be as follows;

In the query above, we accessed the data using Foreign Keys to find employees in the company. In this example we have reached this result with 3 tables and 3 FK, but as the complexity increases, we will be able to access the result using more tables and more FK. The structure will grow and the effort will increase.

Do not forget the above example and let’s analyze the same process in the GraphDB model using Nodes and Edges.

SQL Server GraphDB Example

Create Nodes and Edges Tables

Now insert data into the Node tables. Adding data to Node tables is not different than adding data to normal tables.
To add data to the Edge table, we must provide values for $from_id and $to_id columns from both Nodes.
After insert, SELECT From Nodes;

Select From Edge Tables;

Now we need to write CQL and EXEC to get results from Graph. Our example is to get the names of employees working in a specific company. Accordingly, our CQL is;

As seen in the graph above, we see that the query will need 1 index search.

Now let’s work with different examples,


About Yusuf KAHVECİ

Leave a Reply

Your email address will not be published. Required fields are marked *