5

I'm doing a project in the field of multilevel marketing on .Net and SQL server. In the database it should save like a binary tree. How should i design a database?

markus
  • 39,487
  • 23
  • 96
  • 139
anishMarokey
  • 11,041
  • 2
  • 32
  • 46

3 Answers3

4
id | parentid | name
---------------------
 1 | null     | node1
 2 | 1        | node2
 3 | 1        | node3
Arsen Mkrtchyan
  • 48,710
  • 31
  • 147
  • 181
4

This has been asked and answered before.

Here's a pretty decent tutorial which explains why adjacency model proposed by arsenmkrt is less than ideal.

Community
  • 1
  • 1
ChssPly76
  • 97,371
  • 24
  • 203
  • 192
3

SQL Server 2008 has a built-in data-type called hierarchyid to store hierarchical information. Here are some pointers.

And of course you can do this as mentioned by arsenmkrt in databases other than sqlserver2008.

Community
  • 1
  • 1
this. __curious_geek
  • 41,911
  • 22
  • 111
  • 137