Storing hierarchical data in a database

Tuesday 18 November 2003This is nearly 21 years old. Be careful.

Keeping tree-structured data in a relational database is always a challenge. Storing Hierarchical Data In A Database demonstrates a nifty technique that is heavily tipped toward fast queries. It stores two numbers that link all the nodes together in a depth-first traversal. This makes all sorts of queries possible and efficient, but updating rows is a real pain. If you have data that is read far more often than written, it could be a good choice.

Comments

[gravatar]
I was looking at this problem a few months ago and discovered this great article on an even better way to do it:
http://www.yafla.com/papers/sqlhierarchies/sqlhierarchies.htm

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.