2

I have a tree like graphs and I need to store them into database. I am looking for information how to efficiently store and query graphs in SQL database.

2
  • Highly duplicate question... Maybe pick one implementation, implement it and come back with the code to enhance the performances... Commented Sep 27, 2010 at 10:34
  • I could not find a similar question if you have one, could you include it in your comment? Commented Sep 27, 2010 at 10:44

1 Answer 1

2

Tree graphs, hierarchies, can be stored using the "nested set model". A web search on this term will give you a lot of good articles on this subject. The nested set model allows tree traversal without recursive queries.

The more common approach has a name, "adjacency list model". This approach does require either recursion or DBMS specific extensions to SQL.

The advantage of adjacency lists lies in fast and easy updates. The advantage of nested sets lies in easy queries.

Sign up to request clarification or add additional context in comments.

1 Comment

For a good discussion of these see techportal.ibuildings.com/2009/09/07/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.