Recently a customer asked how to create a Node with an Edge recursively pointing back to the same Node. The use case was around the concept of a Product "recommending" another Product. Here's a conceptual diagram.
How do you create a recursive Edge in SQL Graph tables?
547 views Asked by Jerry Nixon At
1
There are 1 answers
Related Questions in SQL-SERVER
- Dynamic query creation with Array like implementation
- 'pyodbc.Cursor' object has no attribute 'callproc', mssql with django
- Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl, ${SPRING_DATASOURCE_URL}: GitHub Actions
- PHP Laravel SQLServer could not find driver
- Upsert huge amount of data by EFCore.BulkExtensions
- How to locate relevant tables or columns in a SQL Server database
- Cannot delete SQL datafile (.mdf) as its currently in use
- Writing query in CTE returning the wrong output
- Group By Sum and without Group by sum Amount is different
- plan_handle is always different for each query in SQL Server Cache
- Adding a different string to a table fails
- The specified data type in the EF modelBuilder doesn't correspond to the one that is created
- SQL71561: SqlComputedColumn: When column selected
- How to Solve Error Associated with Trusted Authority
- SQL Server Data Model and Insert Performance
Related Questions in SQL-GRAPH
- SQL Server 2022 Graph - Entity developer against T-SQL
- Azure SQL Server edge constraint order
- How to Find Duplicates Over Multiple Columns Using SQL Server
- Referential integrity between a graph node and a table in SQL Server
- Represent an XML Schema and its Data in a SQL Server Graph Schema
- MS SQL Graph Database Node and Edge Table design guidance Require
- SQL Graph Database VS Cosmos Gremlin graph DB
- How do you create a recursive Edge in SQL Graph tables?
- SQL Server Graph Database - shortest path using multiple edge types
- SQL Server : Graph-DB with soft delete isn't working as expected
- SQL Server graph to fetch multiple node types connected to a node
- SQL Server Graph Tables - navigate through certain nodes to find end
- SQL Server Graph: how identify subgraphs?
- SQL Server Graph database
- SQL Server Graph Edge Insert
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)

In SQL Server's SQL Graph, any table can be attributed with one of the DDL extensions
AS NODEorAS EDGE. When an Edge is created it is not directed or constrained, but with the newCONNECTIONkeyword, Edges can be constrained to-and-from only specified Nodes. Let's start with the Products table.This creates an empty table ready to be filled from your RDBMS database for querying with graph queries. You might, for example, want to ask "Does the recommendation chain of THIS product recursively EVER recommend THAT product?" That's a difficult question to ask with a standard TSQL query in any database. It's relatively simple in a graph database.
Here's the magic.
This DDL statement lets you create the Edge you want for recommendation and adds a
CONNECTIONconstraint to ensure the Edge can only be from a Product to a Product and no other Node can participate. Note: you could add ANOTHER constraint if you wanted to reuse this Edge with other Nodes.Now you can answer that question "Does the recommendation chain of THIS product recursively EVER recommend THAT product?" with query something like this:
There are several graph-specific functions built-in to TSQL today. For those missing you have a few interesting options: 1) write your own in TSQL. I have done this on several projects and find it uncommonly straight forward, depending on the algorithm, or 2) consider filtering a subset of the data suited for the algorithm you need and use SQL Server's ML Services capability to expose that data to whatever library your data scientists enjoy most. Having said that, the need to do #2, exporting your data, will be limited to SQL Managed Instance (in Azure) and is super-duper uncommon.