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

  • Home
  • SEARCH
  • 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 6704481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:17:37+00:00 2026-05-26T07:17:37+00:00

this is one on my database tables template. Id int PK Title nvarchar(10) unique

  • 0

this is one on my database tables template.

Id int PK
Title nvarchar(10) unique
ParentId int 

This is my question.Is there a problem if i create a relation between “Id” and “ParentId” columns?
(I mean create a relation between a table to itself)
I need some advices about problems that may occur during insert or updater or delete operations at developing step.thanks

  • 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-26T07:17:38+00:00Added an answer on May 26, 2026 at 7:17 am

    You can perfectly join the table with it self.

    You should be aware, however, that your design allows you to have multiple levels of hierarchy. Since you are using SQL Server (assuming 2005 or higher), you can have a recursive CTE get your tree structure.

    Proof of concept preparation:

    declare @YourTable table (id int, parentid int, title varchar(20))
    
    insert into @YourTable values
    (1,null, 'root'),
    (2,1,    'something'),
    (3,1,    'in the way'),
    (4,1,    'she moves'),
    (5,3,    ''),
    (6,null, 'I don''t know'),
    (7,6,    'Stick around');
    

    Query 1 – Node Levels:

    with cte as (
        select Id, ParentId, Title, 1 level 
        from @YourTable where ParentId is null
    
        union all
    
        select yt.Id, yt.ParentId, yt.Title, cte.level + 1
        from @YourTable yt inner join cte on cte.Id = yt.ParentId
    )
    select cte.*
    from cte 
    order by level, id, Title
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a table named person (in a MySQL database/schema), kind of like this one:
I want to save a query only one time in the database, this is
This one will take some explaining. What I've done is create a specific custom
This one has been bugging me for a while now. Is there a way
I have a legacy data base and a relation one-to-one between two tables. The
No real way for me to succinctly summarize this one. I have two database
i have two tables in my database one is A other one is B
I have two MySQL database tables: one containing a list of championships and another
I have the following problem: I have 3 tables: If you want to create
Hi there I have a short question about database design. I also tried the

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.