1

Since database stores data as 2d table, I want to store treelike data into database, with little space waste.How can I do this?

sandyX
  • 137
  • 10
  • 2
    See http://stackoverflow.com/questions/38801/sql-how-to-store-and-navigate-hierarchies – lreeder Sep 07 '13 at 04:48
  • 1
    This decision also depends on your DBMS. With a modern DBMS recursive queries are easy and quite efficient (in that case the id/parentid approach works fine). But if your DBMS doesn't support that, you will need to find a differetn solution –  Sep 07 '13 at 06:16

1 Answers1

0

Saving data with tree like structure with space: you will run out of space for trees having larger hierachy.

try this

PkId Name  ParentId(FkId to PkId )
---------------------
1    root    0
2    child1  1
3    child2  1
4    child3  2

then you can us a function to generate the tree structure.

sudhansu63
  • 6,025
  • 4
  • 39
  • 52