Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Infinate levels of hierarchal data

Infinate levels of hierarchal data

Scheduled Pinned Locked Moved The Weird and The Wonderful
database
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    asdrog
    wrote on last edited by
    #1

    In many database solutions folk tend to use tables with one to many relationships in order to hierarchal data where as the following achieves the same. ID - Field1 - Field2 - ParentID 1      x      y       0 2      xx    yy      1 3      rr      r       1 4      pr     p      2

    R B 2 Replies Last reply
    0
    • A asdrog

      In many database solutions folk tend to use tables with one to many relationships in order to hierarchal data where as the following achieves the same. ID - Field1 - Field2 - ParentID 1      x      y       0 2      xx    yy      1 3      rr      r       1 4      pr     p      2

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      I won't downvote you for this but it is entirely the wrong place to post your code. If you really want to post this turn it into an article. I would remove it rather quickly if I were you, before it does get downvoted and obliterated.

      "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

      A A 2 Replies Last reply
      0
      • R R Giskard Reventlov

        I won't downvote you for this but it is entirely the wrong place to post your code. If you really want to post this turn it into an article. I would remove it rather quickly if I were you, before it does get downvoted and obliterated.

        "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

        A Offline
        A Offline
        asdrog
        wrote on last edited by
        #3

        Please remove Thread Regards

        R 1 Reply Last reply
        0
        • A asdrog

          Please remove Thread Regards

          R Offline
          R Offline
          R Giskard Reventlov
          wrote on last edited by
          #4

          I don't have the power to do that I'm afraid.

          "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

          1 Reply Last reply
          0
          • R R Giskard Reventlov

            I won't downvote you for this but it is entirely the wrong place to post your code. If you really want to post this turn it into an article. I would remove it rather quickly if I were you, before it does get downvoted and obliterated.

            "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #5

            Top of Page:

            The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

            I'm guessing the OP thinks this is a brilliant data structure (though I don't agree).

            Thou mewling ill-breeding pignut!

            R A 2 Replies Last reply
            0
            • A AspDotNetDev

              Top of Page:

              The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

              I'm guessing the OP thinks this is a brilliant data structure (though I don't agree).

              Thou mewling ill-breeding pignut!

              R Offline
              R Offline
              R Giskard Reventlov
              wrote on last edited by
              #6

              To be fair he is a n00b and the original post had much more code (not that it was any more insightful but we all have to learn, somehow).

              "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

              1 Reply Last reply
              0
              • A AspDotNetDev

                Top of Page:

                The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

                I'm guessing the OP thinks this is a brilliant data structure (though I don't agree).

                Thou mewling ill-breeding pignut!

                A Offline
                A Offline
                asdrog
                wrote on last edited by
                #7

                The illustrated structure is not the normal approach to db design and not tought to everyone, It wasn't in my day. But is now given in some hard back publications, for the intermediate skilled person, as an example of how to use a database to run the .net menu control. Some folk prefer to code XML files to run the .net menu controls, but others prefer a database. Thus allowing one to standardise on using datbases for everything rather than a mix of db and xml on a website.:thumbsup: The structure is also great for managing lists as one does not need one table for the list name and one for the list items, less overhead:thumbsup: For example it is great for the storage of dropdown list values as one can basically use the same sql for all dropdown controls - just passing a different 'ParentID' to get a different data set for the control. This simplifies life in some areas when buildiong a N-Tier Application - Select field1, field2 From table Where ParentID = @ParentID is all you would ever need to code against/use to retrieve any list!:thumbsup: It all boils down to preference, what you need to do and how you have been tought! The structure is not for everyone and everyone should always use what they are happiest using. Happy coding :)

                S 1 Reply Last reply
                0
                • A asdrog

                  In many database solutions folk tend to use tables with one to many relationships in order to hierarchal data where as the following achieves the same. ID - Field1 - Field2 - ParentID 1      x      y       0 2      xx    yy      1 3      rr      r       1 4      pr     p      2

                  B Offline
                  B Offline
                  Bernhard Hiller
                  wrote on last edited by
                  #8

                  Somewhen in the past, hierarchical databases were used. For example, the programming language MUMPS was advertised as a programming language with integrated database - and that database was a hierarchical database. Somewhen later, hierarchical database were given up. Can you guess why?

                  A 1 Reply Last reply
                  0
                  • A asdrog

                    The illustrated structure is not the normal approach to db design and not tought to everyone, It wasn't in my day. But is now given in some hard back publications, for the intermediate skilled person, as an example of how to use a database to run the .net menu control. Some folk prefer to code XML files to run the .net menu controls, but others prefer a database. Thus allowing one to standardise on using datbases for everything rather than a mix of db and xml on a website.:thumbsup: The structure is also great for managing lists as one does not need one table for the list name and one for the list items, less overhead:thumbsup: For example it is great for the storage of dropdown list values as one can basically use the same sql for all dropdown controls - just passing a different 'ParentID' to get a different data set for the control. This simplifies life in some areas when buildiong a N-Tier Application - Select field1, field2 From table Where ParentID = @ParentID is all you would ever need to code against/use to retrieve any list!:thumbsup: It all boils down to preference, what you need to do and how you have been tought! The structure is not for everyone and everyone should always use what they are happiest using. Happy coding :)

                    S Offline
                    S Offline
                    Sentenryu
                    wrote on last edited by
                    #9

                    this way you just take out the meaning of your data.

                    I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                    1 Reply Last reply
                    0
                    • B Bernhard Hiller

                      Somewhen in the past, hierarchical databases were used. For example, the programming language MUMPS was advertised as a programming language with integrated database - and that database was a hierarchical database. Somewhen later, hierarchical database were given up. Can you guess why?

                      A Offline
                      A Offline
                      asdrog
                      wrote on last edited by
                      #10

                      Thenks for the feedback In many instances hierarchical is totally not worth looking at and can be a nightmare to manage, but there is a place for it, and when used with an interface to meet a functionality requirement it can be a great advantage. Expearience has shown that hierarchical data in a single table can be very effective when the user interface mimics that of a file management system to manage the data and you proved breadcumb navigation to go back a level or two. In short - hierarchical data to more than a few levels is not for the faint hearted and even then you realy need to be sure that you understand what you are getting yourself into. (be prepared for developing some prity elaborate loops and/or non pimple coding) Sitting on my bookshelf are numerious intermediate level books that show how to use hierarchical data to power .net sitemap and menu controls from a database rather than xml files. So whilst programming languages like MUMPS have dissapeared there is still a requirement for the strategic use of hierarchical data. The key word being STRATEGIC. For those who want to investigate things further #IHierarchicalDataSource Interface# can be found at http://msdn.microsoft.com/en-us/library/d3ef7363(v=vs.90).aspx #### ASP.net 3.5 Unleashed by Stephen Walther Chapter 19 gives a blow by blow example with sample code for binding a menu control directly to the database - a Hierarchical table. Happy coding :)

                      A 1 Reply Last reply
                      0
                      • A asdrog

                        Thenks for the feedback In many instances hierarchical is totally not worth looking at and can be a nightmare to manage, but there is a place for it, and when used with an interface to meet a functionality requirement it can be a great advantage. Expearience has shown that hierarchical data in a single table can be very effective when the user interface mimics that of a file management system to manage the data and you proved breadcumb navigation to go back a level or two. In short - hierarchical data to more than a few levels is not for the faint hearted and even then you realy need to be sure that you understand what you are getting yourself into. (be prepared for developing some prity elaborate loops and/or non pimple coding) Sitting on my bookshelf are numerious intermediate level books that show how to use hierarchical data to power .net sitemap and menu controls from a database rather than xml files. So whilst programming languages like MUMPS have dissapeared there is still a requirement for the strategic use of hierarchical data. The key word being STRATEGIC. For those who want to investigate things further #IHierarchicalDataSource Interface# can be found at http://msdn.microsoft.com/en-us/library/d3ef7363(v=vs.90).aspx #### ASP.net 3.5 Unleashed by Stephen Walther Chapter 19 gives a blow by blow example with sample code for binding a menu control directly to the database - a Hierarchical table. Happy coding :)

                        A Offline
                        A Offline
                        AspDotNetDev
                        wrote on last edited by
                        #11

                        You may be interested in another way of doing hierarchical data in a table. It looks a bit like this:

                        Id

                        ParentId

                        IdPath

                        WhateverData

                        1

                        NULL

                        1

                        Blah

                        2

                        1

                        1_2

                        Blah

                        3

                        1

                        1_3

                        Blah

                        4

                        NULL

                        4

                        Blah

                        5

                        2

                        1_2_5

                        Blah

                        6

                        5

                        1_2_5_6

                        Blah

                        If you include the full path of ID's (the ID and all ancestor ID's), you can reduce the number of queries required to get all descendents of a record. I think newer versions of SQL Server have some ability to query hierarchical data, but this approach will work on all SQL systems.

                        Thou mewling ill-breeding pignut!

                        A 1 Reply Last reply
                        0
                        • A AspDotNetDev

                          You may be interested in another way of doing hierarchical data in a table. It looks a bit like this:

                          Id

                          ParentId

                          IdPath

                          WhateverData

                          1

                          NULL

                          1

                          Blah

                          2

                          1

                          1_2

                          Blah

                          3

                          1

                          1_3

                          Blah

                          4

                          NULL

                          4

                          Blah

                          5

                          2

                          1_2_5

                          Blah

                          6

                          5

                          1_2_5_6

                          Blah

                          If you include the full path of ID's (the ID and all ancestor ID's), you can reduce the number of queries required to get all descendents of a record. I think newer versions of SQL Server have some ability to query hierarchical data, but this approach will work on all SQL systems.

                          Thou mewling ill-breeding pignut!

                          A Offline
                          A Offline
                          asdrog
                          wrote on last edited by
                          #12

                          Nice alternative, but not sure how easilly it could be used to power a menu control. With regards to reducing SQL work I can see that it would have benifits.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups