Questions tagged [sql-graph]

SQL Graph is a subset capability of every edition of SQL Server (SQL Express, Professional, Enterprise, Azure) since SQL Server version 2017. It enables Nodes and Edges inside SQL Server that support graph-specific queries that leverage Graph Theory to navigate through data as nouns and verbs.

SQL Server offers graph database capabilities to model many-to-many relationships. The graph relationships are integrated into Transact-SQL and receive the benefits of using SQL Server as the foundational database management system.

What is a graph database?

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. Here are some features that make a graph database unique:

  • Edges or relationships are first class entities in a Graph Database and can have attributes or properties associated with them.
  • A single edge can flexibly connect multiple nodes in a Graph Database.
  • You can express pattern matching and multi-hop navigation queries easily.
  • You can express transitive closure and polymorphic queries easily.

When to use a graph database

A relational database can achieve anything a graph database can. However, a graph database makes it easier to express certain kinds of queries. Also, with specific optimizations, certain queries may perform better. Your decision to choose either a relational or graph database is based on following factors:

  • Your application has hierarchical data. The HierarchyID datatype can be used to implement hierarchies, but it has some limitations. For example, it does not allow you to store multiple parents for a node.
  • Your application has complex many-to-many relationships; as application evolves, new relationships are added.
  • You need to analyze interconnected data and relationships.
42 questions
11
votes
2 answers

Cosmos db graph vs Azure Sql Server - Performance and cost

Imagine a social network app. Users follow other users and users take photos. Photos have tags of other users. I'm trying to get an effective Cosmos db implementation of a graph for that app. I provide an SQL Server version as well as a…
François
  • 3,164
  • 25
  • 58
9
votes
1 answer

Graph problems: connect by NOCYCLE prior replacement in SQL server?

question: I have the following (directed) graph: And this table: CREATE TABLE [dbo].[T_Hops]( [UID] [uniqueidentifier] NULL, [From] [nvarchar](1000) NULL, [To] [nvarchar](1000) NULL, [Distance] [decimal](18, 5) NULL ) ON…
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442
7
votes
1 answer

Perfomance SQL Server 2017 Graph vs Neo4j

I am researching about graph databases. I stumbled into SQL Server 2017 and learned that they added the option to use a graph database. But I have some uncertainties about the performance. I watched several Youtube videos, tutorials and papers about…
7
votes
2 answers

Syntax for Entity Framework query to SQL Server 2017 Graph database

Assume I'm working with the graph database from this sample (SQL Server 2017): https://learn.microsoft.com/en-us/sql/relational-databases/graphs/sql-graph-sample I have the following SQL query: -- Find Restaurants that John likes SELECT…
gbdavid
  • 1,639
  • 18
  • 40
6
votes
3 answers

Efficiently querying a directed/undirected table of graph edges in SQL Server

I've got a SQL server table in which each row represents an edge in a graph network. The FromNodeID and ToNodeID are foreign keys to a node table, and the schema is something like this: CREATE TABLE #Edges ( EdgeID int identity (1,1), FromNodeID…
Clare Nia
  • 105
  • 1
  • 3
4
votes
2 answers

How to prevent insertion of cyclic reference in SQL

I have the following table: create table dbo.Link ( FromNodeId int not null, ToNodeId int not null ) Rows in this table represent links between nodes. I want to prevent inserts or updates to this table from creating a cyclic relationship…
fractor
  • 1,534
  • 2
  • 15
  • 30
3
votes
0 answers

Storing Routes and Locations in Graph using SQL Server 2017

I'm very new to Graph database, so please ignore my mistakes. My scenario described in following picture: I have different locations connected to each other with a route between them. Then I have many outlets linked to routes. I created a RDBMS…
صفي
  • 1,068
  • 2
  • 15
  • 34
3
votes
1 answer

Fetching all the paths between two nodes using SQL Server Graph 2017

I found many examples of fetching paths between 2 nodes in neo4j and gremlin but could not find any on SQL Server Graph 2017. Though it uses Cypher's Match, I was thinking if it is possible to find the path using only Match? Thanks in advance!
fdabhi
  • 309
  • 4
  • 11
3
votes
1 answer

Syntax to query for optional relationships in Microsoft SQL Server 2017 Graph Database?

I want to select optional relationships in sql-server-2017-graph. Similar to optional in sparql e.g.: PREFIX foaf: SELECT ?name ?mbox WHERE { ?x foaf:name ?name . OPTIONAL { ?x foaf:mbox ?mbox } } from…
2
votes
1 answer

SQL Server Graph Database - shortest path using multiple edge types

I have done my research on SQL Server GraphDB, but all the contrived examples I've found so far use only a single edge table. It's always Person-friend_of->Person, for example. In my case, I've created a graph of deployed software components in our…
Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
2
votes
1 answer

SQL Server Graph: how identify subgraphs?

I have [Friends] node and [Link] edge. My task is to figure-out which friend to which subgraph(network) belongs. Simple illustration of this: Here is my code how I construct nodes, edges and populate the data: -- Construct nodes DROP TABLE IF…
Juozas
  • 916
  • 10
  • 17
2
votes
1 answer

sql server graph query, find all paths to node

I have a very common problem I am trying to solve using graph queries (sql server 2017). I want to build a query and find how anyone in the nodes is connected to C. I want to build a query and find how anyone in the nodes is connected to C…
SexyMF
  • 10,657
  • 33
  • 102
  • 206
2
votes
1 answer

Querying SQL Server 2017 graph tables from EF

I'd like to use graph datatables features from EF 6, but after a lot of research, it seems that it's not supported yet. Is stored procedures the only way to go using graph tables from EF at this moment?
Oscar
  • 13,594
  • 8
  • 47
  • 75
2
votes
1 answer

Combining data from Sql Server and Graph database

In my C# project I have relationship stored in graph database and I want to pull the data based on relationship from Sql Server, which is my main data base. What would be the best approch to pull the data fron these two databases.
2
votes
1 answer

SQL Server 2008R2 from Table to edges for Graph

I have stumbled upon an interesting challenge. I have data in a SQL Server table with the following format/content. Date | Name ---------+--------- 1/1/2010 | John 1/1/2010 | Mark 1/1/2010 | Peter 1/1/2010 | Mia 2/4/2010 | John 2/4/2010 |…
lwall
  • 87
  • 1
  • 10
1
2 3