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.
+1
A:
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.
Walter Mitty
2010-09-27 22:50:45
For a good discussion of these see http://techportal.ibuildings.com/2009/09/07/graphs-in-the-database-sql-meets-social-networks/
CurtainDog
2010-09-27 23:09:24