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
  • 40,136
  • 23
  • 97
  • 142
anishMarokey
  • 11,279
  • 2
  • 34
  • 47

3 Answers3

4
id | parentid | name
---------------------
 1 | null     | node1
 2 | 1        | node2
 3 | 1        | node3
Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
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
  • 99,456
  • 24
  • 206
  • 195
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
  • 42,787
  • 22
  • 113
  • 137