Results 1 to 6 of 6
  1. #1
    gcw is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    2

    Help with possible many-to-many relationship

    Hi all - I'm a newbie here so please forgive any clumsiness/lack of knowledge...



    I have a database which essentially concerns a number of objects. Each object has various pieces of unique information, and two lookups, namely find-spot and place of production. My find-spots lookup is fine, but I am having some difficulties with place of production, because while most objects have only one place of production, some have two.

    My initial solution was to have two 'place of production' fields, each linked to the same lookup table. But when I run queries based on place of production, it won't pull out all the records I need (ie if I ask for place of production A, I get all records that only have place of production A, not those that have A & B)

    It seems to me that I need a many-to-many relationship, but I have played around with this and can't seem to make it work. One of the problems is that, because I am the only user of the database, I tend to enter data straight into the tables (ie the objects table), and with a many-to-many relationship I feel like I have nowhere in the objects table to mark the place of production.

    Any help greatly appreciated. Thanks!

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    If an object can be produced in many places and a production place can have many objects associated with it, then you do have a many-to-many relationship which requires 3 tables

    tblObjects
    -pkObjectID primary key, autonumber
    other fields that pertain ONLY to the object

    tblPlaces
    -pkPlaceID primary key, autonumber
    -txtNameOfPlace
    other fields that pertain ONLY to the place


    tblObjectPlaces
    -pkObjPlaceID primary key, autonumber
    -fkObjectID foreign key to tblObjects
    -fkPlaceID foreign key to tblPlaces

  3. #3
    gcw is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    2
    Thanks jzwp11. That was a set up I had looked at, but it seemed to me that every time I enter an object, I'm then going to have to go to the ObjectPlaces table to associate it with a place of production. This doesn't seem very efficient.

    Another suggestion that has been made to me was to have multiple versions of those objects that have more than one place of production (it's fewer than 10% in all). So the objects table would look something like this:

    ObjectVersion Place (lookup) Count OtherInfo
    001 A 0 xxx
    002:1 A 1 xxx
    002:2 B 2 (null)

    So any object with one place of production has "count"=0, and any with multiple place of production has two records, one with "count"=1 and one with "count"=2. Then to run a query, I can ask for either 0s & 1s, or 0s & 2s, to avoid selecting multiple versions of the same object. I am extremely wary of not having a system whereby 1 object = 1 record, and am also not sure how I can get "OtherInfo" associated with version 1 to also associate with version 2 without manually entering it a second time.

    I don't like this second idea much, but wanted to mention it to see other people's thoughts, and because the many-to-many relationship as I see it currently doesn't quite function as I need.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746

  5. #5
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    The properly normalize way is as I showed in my post. If things change over time (>10%) you can be setting yourself up for problems.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    I agree with jzwp11, and I would add that I would make a unique compound index of these 2 fields
    -fkObjectID foreign key to tblObjects
    -fkPlaceID foreign key to tblPlaces

    in tblObjectPlaces.

    This will prevent duplicates in this table.
    Good luck

Please reply to this thread with any new information or opinions.

Similar Threads

  1. One to Many relationship
    By ramindya in forum Access
    Replies: 4
    Last Post: 02-10-2012, 01:59 PM
  2. Relationship
    By Navop in forum Database Design
    Replies: 1
    Last Post: 01-16-2012, 02:52 AM
  3. relationship
    By slimjen in forum Forms
    Replies: 1
    Last Post: 09-26-2011, 07:15 PM
  4. One to one relationship
    By anemoskkk in forum Access
    Replies: 1
    Last Post: 04-13-2011, 12:05 PM
  5. Relationship
    By ClownKiller in forum Database Design
    Replies: 13
    Last Post: 12-21-2010, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums