Re: Database design for tree structure




<wing0508@xxxxxxxxx> wrote in message
news:1151124216.568320.263160@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
: Dear All
:
: I have designed a database which for tree structure.
:
: the table design as like as follow
:
: id BIGINT
: parentid BIGINT
: name VARCHAR
: depth INT
: path VARCHAR
:
: the record as like as follow
: id parentid name depth path
: 1 0 - 0 .1.
: 2 1 food 1 .1.2.
: 3 1 toy 1 .1.3.
: 4 2 noodle 2 .1.2.4.
: 5 2 game 2 .1.3.5.
:
: The above example can reduce the retrieval process
: For example, I need can the nodes under the root (id = 1), than I can
: using single sql statement to retrieve all nodes by using the field
: "path"
: If I want to get the nodes under the food (id = 2), than I can using
: single sql statement to retrieve all nodes by using the field "path"
: again.
:
: However, the above structure cannot handle the sorting, if i want to
: sort by name, it cannot be done, any design than can reduce the
: complexity of sql statement but still can sorting by using the name?
:
: Thanks
:

oracle's CONNECT BY hierarchical query syntax handles this, including its
ORDER SIBLINGS BY clause

you don't need path or depth -- that's derived data and would need to be
recalculated for an entire branch when updating PARENT_ID

see http://www.psoug.org/reference/connectby.html for some examples or
search tahiti.oracle.com for 'hierarchical queries'

++ mcs


.



Relevant Pages

  • Re: OT: MySQL versus PostgreSQL and database design
    ... and avoiding an absolute "the design is broken" pronouncement. ... to retrieve all the events at once. ... in a way that you can avoid any real searching in your application, ... can make that a primary key in the database. ...
    (rec.crafts.metalworking)
  • Re: Going to Design View...
    ... This is a totally unbound form, and closing from the btnExit command button doesn't cause the error, only going from form view to design view by either the ribbon or context menu. ... What are you attempting to retrieve? ... msgbox "Unload" ...
    (comp.databases.ms-access)
  • Re: expiration
    ... Driver's License expiration, Professional License expiration, FBI clearance ... This query is based off the existing employee database created by someone ... design a query, Access builds the SQL statement behind the scenes. ... it is the actual SQL statement that is executed. ...
    (microsoft.public.access.queries)
  • Re: Access XP / MySQL / MyODBC: Access caching system?
    ... you retrieve ten times the amount of data you need), ... think for a change -- what environment was Access/Jet designed ... But that whole design is based on the assumption that there is no ... Once you've got a server on the other end, ...
    (comp.databases.ms-access)
  • Re: expiration
    ... Will this new query be based off of a table or another query? ... SQL is the language/code that Access uses to execute queries. ... design a query, Access builds the SQL statement behind the scenes. ... it is the actual SQL statement that is executed. ...
    (microsoft.public.access.queries)