Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6365175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:15:37+00:00 2026-05-25T00:15:37+00:00

Is there a tool that works with SQL Server to generate tree-like diagrams from

  • 0

Is there a tool that works with SQL Server to generate tree-like diagrams from a hierachical data model?

I am working with a large geographical hierarchy, and would like to visualize it.

Here is an example.

I have a NodeHierarchy table that stores a hierarchical relationship among nodes. Each row in the table represents a node. Each node but one has a parent node. The node that has no parent is the root if the hierarchy.

Here is how I create my table:

CREATE DATABASE HierarchyTest;
GO

USE HierarchyTest;
GO

CREATE TABLE NodeHierarchy (
  PK_NodeID INT NOT NULL
    CONSTRAINT PK_NodeHierarchy PRIMARY KEY,
  FK_ParentNodeID INT NULL
    CONSTRAINT FK_NodeHierarchy_NodeHierarchy FOREIGN KEY
      REFERENCES NodeHierarchy(PK_NodeID),
  Name NVARCHAR(255) NOT NULL
);

I have an example hierachy of Scottish cities and venues. Scotland is the root of the hierachy. The descendants of Scotland are cities and venues. In this hiearchy, a parent ‘contains’ a child, so we say that e.g. “The Barrowlands is in Glasgow, and Glasgow is in Scotland”.

This statement populates the NodeHierachy table with eample data:

INSERT INTO NodeHierarchy(PK_NodeID, FK_ParentNodeID, Name)
VALUES
  (1, NULL, N'Scotland'),
  (2, 1, N'Glasgow'),
  (3, 1, N'Edinburgh'),
  (4, 1, N'St Andrews'),
  (5, 2, N'The Barrowlands'),
  (6, 2, N'The Cathouse'),
  (7, 2, N'Carling Academy'),
  (8, 2, N'SECC'),
  (9, 2, N'King Tut''s Wah-Wah Hut'),
  (10, 3, N'Henry''s Cellar Bar'),
  (11, 3, N'The Bongo Club'),
  (12, 3, N'Sneaky Pete''s'),
  (13, 3, N'The Picture House'),
  (14, 3, N'Potterrow'),
  (15, 4, N'Aikman''s'),
  (16, 4, N'The Union'),
  (17, 4, N'Castle Sands');

Output of SELECT * FROM NodeHierarchy;:

PK_NodeID   FK_ParentNodeID Name
----------- --------------- ---------------------------------
1           NULL            Scotland
2           1               Glasgow
3           1               Edinburgh
4           1               St Andrews
5           2               The Barrowlands
6           2               The Cathouse
7           2               Carling Academy
8           2               SECC
9           2               King Tut's Wah-Wah Hut
10          3               Henry's Cellar Bar
11          3               The Bongo Club
12          3               Sneaky Pete's
13          3               The Picture House
14          3               Potterrow
15          4               Aikman's
16          4               The Union
17          4               Castle Sands

(17 row(s) affected)

In Freemind I drew this equivalent diagram:
mindmap of Scottish venues

What tool can do this for me with a minimum of manual effort?


EDIT: Originally I said that I wanted to visualize “all or part” of the hierarchy. The solution posted here visualizes the entire hierarchy unconditionally. This is fine for the small example hierarchy, but for a larger one, it may be more useful to visualize only part of it.

Because I didn’t specify what I meant by “part”, I have removed this from the question. I have asked about partial visualization in another question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:15:37+00:00Added an answer on May 25, 2026 at 12:15 am

    I researched the leads in Cade Roux’s answer and developed a solution using GraphViz.

    To understand GraphViz, first I read this introductory article and the Command-line Invocation documentation. After successfully generating graphs from the example code listing in the article, I felt confident to work with my own data.

    As Cade suggested, the best way to learn GraphViz’s DOT language is to write it out myself. I studied the article’s examples (Listings 1, 2, and 6) and then came up with this venues.gv to describe my own data:

    digraph Venues
    { 
      N1[label = "Scotland"];
      N2[label = "Glasgow"];
      N3[label = "Edinburgh"];
      N4[label = "St Andrews"];
      N5[label = "The Barrowlands"];
      N6[label = "The Cathouse"];
      N7[label = "Carling Academy"];
      N8[label = "SECC"];
      N9[label = "King Tut's Wah-Wah Hut"];
      N10[label = "Henry's Cellar Bar"];
      N11[label = "The Bongo Club"];
      N12[label = "Sneaky Pete's"];
      N13[label = "The Picture House"];
      N14[label = "Potterrow"];
      N15[label = "Aikman's"];
      N16[label = "The Union"];
      N17[label = "Castle Sands"];
    
      N1 -> N2;
      N1 -> N3;
      N1 -> N4;
      N2 -> N5;
      N2 -> N6;
      N2 -> N7;
      N2 -> N8;
      N2 -> N9;
      N3 -> N10;
      N3 -> N11;
      N3 -> N12;
      N3 -> N13;
      N3 -> N14;
      N4 -> N15;
      N4 -> N16;
      N4 -> N17;
    }
    

    I fed this to circo, just one of the many graph-drawing commands that are part of GraphViz, and got pleasing output:

    Output of circo -Tpng venues.gv -o venues.png:

    Visualization of hierarchical venue data

    The GraphViz file is structured in two blocks. One block declares a label for each node, and the other block declares the edges of the graph.

    To provide the data for each of these blocks, I created a view of NodeHierarchy.

    This view provides the data to declare labels for nodes:

    CREATE VIEW NodeLabels (
      Node,
      Label
    )
    AS
    SELECT
       PK_NodeID AS Node,
       Name AS Label
    FROM
      NodeHierarchy;
    

    This view provides the data to declare edges between nodes:

    CREATE VIEW Edges (
      Parent,
      Child
    )
    AS
    SELECT
      FK_ParentNodeID AS Parent,
      PK_NodeID AS Child
    FROM NodeHierarchy
    WHERE FK_ParentNodeID IS NOT NULL;
    

    This Powershell script called generate-graph.ps1 selects the data from the views, transforms it into a GraphViz input, and pipes it to circo to produce a visualization of the full hierarchy like the one above:

    "digraph Venues {" + (
      Invoke-Sqlcmd -Query "SELECT * FROM HierarchyTest.dbo.NodeLabels" | 
      ForEach-Object {"N" + $_.Node + "[label = """ + $_.Label + """];"}
    ) + (
      Invoke-Sqlcmd -Query "SELECT * FROM HierarchyTest.dbo.Edges" |
      ForEach-Object {"N" + $_.Parent + " -> N" + $_.Child + ";"}
    ) +
    "}" | circo -Tpng -o venues.png
    

    The script must be run in sqlps instead of powershell so that the Invoke-Sqlcmd cmdlet is available. The default working directory of sqlps is SQLSERVER, so I have to specify the drive when I run the script through sqlps.

    This is the command I use to generate a graph like the one above:

    sqlps C:.\generate-graph.ps1
    

    This outputs a file called venues.png in the C working directory.

    This Powershell solution feels a little inelegant, but this does what I need it to do. A more experienced Powershell programmer might be able to come up with something cleaner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a tool that can generate sequence diagrams from running .NET code?
Is there any tool that can parse a valid C program and generate a
Is there a tool that can parse C++ files within a project and generate
Is there an automatic way in SQL Server 2005 to create a database from
Is there a tool that will find for me all the css classes that
Is there a tool that allows one to monitor GDI calls?
Is there any tool that enables you to hot swap JavaScript contents while executing
Is there a tool that will take you java beans (pojos) and automatically make
Is there a tool that will show me what applications are writing to the
Is there any tool that lists which and when some classes are effectively used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.