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 719493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:38:54+00:00 2026-05-14T05:38:54+00:00

I want to store website page hierarchy in a table. What I would like

  • 0

I want to store website page hierarchy in a table.

What I would like to achieve is efficiently
1) resolve (last valid) item by path (e.g. “/blogs/programming/tags/asp.net,sql-server”, “/blogs/programming/hello-world” )
2) get ancestor items for breadcrump
3) edit an item without updating the whole tree of children, grand children etc.

Because of the 3rd point I thought the table could be like

ITEM
id    type        slug           title               parentId
1     area        blogs          Blogs
2     blog        programming    Programming blog    1
3     tagsearch   tags                               2
4     post        hello-world    Hello World!        2

Could I use Sql Server’s hierarchyid type somehow (especially point 1, “/blogs/programming/tags” is the last valid item)?
Tree depth would usually be around 3-4.

What would be the best way to achieve all this?

  • 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-14T05:38:54+00:00Added an answer on May 14, 2026 at 5:38 am

    The way you have done this seems fine, you can make use of CTE recursive functions to create the hierarchy for you

    Something like

    DECLARE @ITEM  TABLE(
            id INT,
            type VARCHAR(20),
            slug VARCHAR(50),
            title VARCHAR(50),
            parentId  INT
    )
    
    INSERT INTO @ITEM SELECT 1,'area','blogs','Blogs', NULL
    INSERT INTO @ITEM SELECT 2,'blog','programming','Programming blog',1 
    INSERT INTO @ITEM SELECT 3,'tagsearch','tags',',',2 
    INSERT INTO @ITEM SELECT 4,'post','hello-world','Hello World!',2 
    
    ;WITH Items AS (
            SELECT  *,
                    CAST('/' + slug + '/' AS VARCHAR(50)) PathVal
            FROM    @ITEM
            WHERE   parentId IS NULL
            UNION ALL
            SELECT  i.*,
                    CAST(Items.PathVal + i.slug + '/' AS VARCHAR(50))
            FROM    Items INNER JOIN
                    @ITEM i ON i.parentId = Items.ID
    )
    
    SELECT  *
    FROM    Items
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this page table structure to store all the website page information, page_id
I want to crawl a website and store the content on my computer for
For my website I want to store the general format of the site in
There is a certain page on my website where I want to prevent the
I want to be able to store website configuration without the use of mysql.
I want to implement a simple in-house table that tracks user page views on
Let's assume i have a website like quora where i want to count how
I want to store my static website in azure blobs. My question is, what
I want to store a user's current location on an ASP.NET MVC website for
Ok guys I'm using xml to store page information for a dynamic website. I

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.