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 > 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
Post a Comment