Results 1 to 3 of 3

Thread: one to many to many

  1. #1
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default one to many to many

    nothing i have found online can help me with the problem I am having. I am trying to build a db on the assembly of a printer, however I am getting stuck with what to create for tables. All of the tutorials i have been able to find say that there need to be at least 3 tables to preform this action,however I dont really understand that fact. There are assemblies that contain other assemblies, now at first I thought about doing 1 table of all assemblies and 1 table of non-assembly parts, however you cannot have a table look at itself hense the third table... so do I make duplicate tables with a full list of all of the parts?? I am really lost on how I am going to set this database up. Any help would be very helpful. Thanks

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    however you cannot have a table look at itself hense the third table...
    Yes you can. Self-referencing relationships are common.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2007
    Location
    Virginia Beach, VA USA
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The three table approach involves creating a table called assemblies and a second table called parts. The third table includes a primary id field plus foreign key fields for the assemblies and parts tables. The third table allows you to relate any number of parts with any number of assemblies. For a simple assemblies table, you could use the adjacency list model which uses a parent_id field to create your top-down breakdown of assemblies and subassemblies. The parts table lists the actual parts, part numbers, vendors, pricing, etc.

    An alternate approach is to use the nested sets model (also called modified inverse preorder tree traversal) which uses a single table to mimic a hierarchial tree structure in a RDBMS. The original concept was developed by Joe Celko (DBA guru) and there are numerous articles on the web regarding this topic, plus he wrote a book on the subject called "Joe Celko's Trees and Hierarchies in SQL for Smarties", ISBN:1-55860-920-2.

    You might try doing some web searches on "nested sets", "Joe Celko", "tree traversal", etc. There are numerous other solutions based on the original nested sets model that improve the original concept if you need further enhancements.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •