Tuesday, March 20, 2012

parent -> child relationship (same table)

Is it best to store the parent/child relationships in seperate tables? What are the pro/cons to this situation vs. storing the parentid in the same row (ie: id-parentid-itemname)

For an online catalog where you'd like to display a single item in multiple categories, are different tables the best way to do this?

How about an online directory listing (similar to yahoo.com's main page)?

Links, pre-developed products, etc. welcome. I'm new to doing this type of thing!For your example:

Product Table:
ProductID
ProductDescription
-- etc.

Category Table:
CategoryID
CategoryName
-- etc.

CategoryProductLink Table:
CategoryID
ProductID
-- etc.|||Putting the relationship in another table will allow you to assign multiple parents for a given node. Beside that you'll encounter the same problems in both situation like getting the children or parents of a given node.

No comments:

Post a Comment