Self Review: Practical Graph Structures in SQL Server and Azure SQL

I just finished writing this book a few weeks ago, and as I read it, I thought “why not review my own book?” Of course, the question that first comes to mind is “are you insane?” It seems like a no-win proposition. Anything less than “best book evah” and it will seem like false modesty. In reality what I want to do is write out my feelings on where SQL Server’s feature is, what I covered, and how I feel about it.

Today the book arrived at my doorstep and I knew this is the time to press upload on this blog too.

This is a book I have worked on for many years informally, but over two and a half years ago, I sent my proposed table of contents to my then-editor Jonathan Gennick. Jonathan works for a different publisher now but is still listed as the book’s editor.

In other words, I worked really hard on this book on and off for a very long time. (The off times were both health-related and my hopes for SQL Server 2022 to make even more progress.) I had high hopes for it, and in the end… well, let’s not give it away yet. Am I proud of this book? Yes, and not just because of the likelihood that Apress wouldn’t let me write again if I didn’t say I was. Honestly, if I wasn’t proud of the book, I would I have done what I could to quit the project.

I do fear two things:

  1. I missed something huge and/or fantastic in the tool
  2. I get complaints because I don’t go deep enough into all the different uses of graphs.

One thing I wanted to make clear when I wrote this is that it is a book about programming in T-SQL as of May 2023. I did start out the book with a bit of theory and a little design, but what I set out to show was to give examples of everything you can do right now in T-SQL. In this task, I think. I did at the very least, adequately.

While it is not reflected in the book, as I was thinking about how to describe the content, I realized the book really could be considered to have 3 main sections:

Section 1: Chapters 1 and 2 basically try to establish what a graph is, how it can be used, etc. If I do a second edition someday, this will likely need to be deeper. But it is what led me down the path to working with graph structures.

Section 2: Chapters 3 and 4 are syntax and techniques. Showing how the SQL Server Graph objects work, showing off the specific SQL Graph syntax. In some respects, this goes back to using things like recursive CTEs where useful.

Section 3: The last four chapters of the book give some basic examples of how to use a graph.

  • Chapter 5 implements the tree structure using SQL Graph.
  • Chapter 6 shows an alternative solution for storing a graph, adds helper tables to optimize viewing data from the graph, and then shows how queries using all the methods perform.
  • Chapter 7 implements a directed acyclic graph that is not a tree, showing a few techniques that use SQL Graph syntax specifically and some of the ways you get around current limitations.
  • Chapter 8 contains a relatively simple network structure that implements people following each other and their interests. It, too, shows the performance of different queries.

It is probably not a big surprise that SQL Server’s graph implementation is fairly weak at this point and that they did not make any syntactical changes to the feature in 2022. The stark reality is, if no one uses this feature, it may languish for years to come. Even with the product’s limitations, it is a useful feature once you get past the somewhat complex syntax used to work with graph data in SQL Server. And putting this graph syntax together with basic relational coding can give you something pretty useful.

The bottom line is that I feel like If you want to use the SQL Server graph feature in your company software, this book will do well in introducing and demonstrating the feature as it stands in SQL Server 2022. But of course, that is my opinion; I look forward to your opinion. You can email me at louis@drsql.org if you have comments, negative or positive.

I will also occasionally peek at the reviews on Amazon and other booksellers, so please say if you have feelings or things I should add to a future iteration of the book. Anything I learn will show up on this blog and in my github repository: https://github.com/drsqlgithub/GraphBook1 .