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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:01:13+00:00 2026-06-09T12:01:13+00:00

I have a table which will contain various categories. The following is a minified

  • 0

I have a table which will contain various categories. The following is a minified table structure:

tb_categories
  category_id
  category_name
  category_parent_id

I created a foreign key constraint on category_parent_id on the category_id so data integrity can be held within the same table.

First question is, is it good practice to have a foreign key on the same table. From my way of thinking I am thinking that yes in such a case, it is a good practice.

Second question is, what is the best approach on how to store the global parent entity?

I came up with the following methods:

Method 1: category_parent_id can store nulls and the only null is the global parent category entitled All

Method 2: category_parent_id cannot store nulls and the global parrent ALL will contain its same category_id. Therefore, for only this category, both category_id and category_parent_id will be identical. Without nulls, I cannot insert this category_parent_id as 0 since 0 does not exist as a category_id

Method 3: Not having a global parent and there will be different ‘parents’. For example, having Audio, Visual as parents and MP3, WMA as Audio’s children and MPEG, AVI as Visual’s children. Throughout this method, the same principles of methods 1 and 2 applies.

Method 4: This is the least method which I prefer which includes in not having this foreign key constraint and thus the global parent can be set to 0 which does not exist in any other category.

Any suggestions? As I am looking for the best practice and not something that ‘just works’.

  • 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-06-09T12:01:14+00:00Added an answer on June 9, 2026 at 12:01 pm

    It is normal to have a table refer itself. There are a lot of real world scenarios that need this situation (Employee -> Manager is a famous textbook example).

    And, you will end up having a “global” parent whether it is a single global parent or multiple global parents. So you need to come up with an approach.

    I prefer method 1 – an element without a parent will have no parent at all, because, well, it exactly realizes your business rule.

    Having a 0 or referring self as parent will create problems when you have complex queries

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

Sidebar

Related Questions

I have created an archive table which will store data for selecting only. Daily
I have the following code, which will retrieve a filename from a table and
I have a table in mdb with field address, which will contain street address
I have a table with various fields 2 of which contain a number between
I have table which will only contain information about files, so, as the file
What I can think of is: Algo: Have a hash table which will store
if i have a table which has columns with fixed lenght, Will mySQL count
I have this method which will remove all rows from a table but I
I have a MySQL table, in which I will be storing the email_id of
I am creating BOOK_Issue table which will contain id of person to whom 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.