database - Should I use a Foreign Key to Show Tree Relationship in SQL -


I am trying to model a tree relation in a table. For example, there are "categories" and the categories themselves can be within a parent category.

My schema is:

  ID primary primary key, parent_id int, name 

code>

My question is, do I have a parent_id Should the column be labeled as a foreign key? Foreign means "outside" and not self-referenced. Is there a different type of key for this purpose?

My question is the same :, but I am asking a different question, due to no problem > itemprop = "text">

Self-referencing foreign keys happen all the time, such as an employee may have another "employee" as its manager, so the manager_id one In the same table, the employee_id will be a foreign key of the field.

Foreign keys are natural candidates to represent parent nodes in hierarchical data, although they are not specifically used for it :)


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -