I am doing a multi-level marketing project on .Net and SQL server. In the database, it should save as a binary tree. How do I create a database?
SQL Server 2008 has a built-in data type called hierarchyid for storing hierarchical information. Here are a few pointers.
http://blogs.msdn.com/manisblog/archive/2007/08/17/sql-server-2008-hierarchyid.aspx
http://technet.microsoft.com/en-us/library/bb677290.aspx
And of course, you can do this as indicated by arsenmkrt in databases other than sqlserver2008.
That was and answered before .
Here's a pretty decent tutorial that explains why the adjacency model proposed by arsenmkrt is less than ideal.
id | parentid | name --------------------- 1 | null | node1 2 | 1 | node2 3 | 1 | node3