Results 1 to 9 of 9
  1. #1
    mountainclimber is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    56

    one to many relationship

    Hello.



    I am setting up relationships in MS Access. In the screen shot below I have the relationship ColName and Factor.
    Click image for larger version. 

Name:	Capture.PNG 
Views:	12 
Size:	8.5 KB 
ID:	21518

    ColName has all of the unique 'names' listed. There are about 1350 of them. The field Factor has a massive list of 800k names with many repeats of the names. However, all of the 800k names can be found in the ColName field in the tbl_NameDescs table.

    I have made this relationship for two reasons:
    1) To maintain name integrity: so the names can only be changed in one place and all names are found in any table can be found in tbl_NameDescs
    2) To save space: I don't have to list the same name over and over again in the Factor field.

    My question:
    In #2 above, when I created the relationship (dragging and dropping while in relationships) the Factor field still lists all of the names. How is that saving space? Shouldn't the names be replaced with an ID or something in the Factor field? ColName and Factor are Text fields.

  2. #2
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Why do you have 4 primary keys in tbl_HistStatsSettings?
    If all the names can be found in ColName that are in field 'Factor' then Factor wouldn't be the primary key, especially since you said the field factor has many repeats. I don't think it exactly 'saves space' by making these relationships, unless you have an index made it just makes lookup/reference easier for access to conduct on that field. Otherwise relationships just help to normalize the data.

    Typically relationships are 1 --> many, and are Primary Key (1) --> Foreign Key (many).

  3. #3
    mountainclimber is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    56
    Quote Originally Posted by nick404 View Post
    Why do you have 4 primary keys in tbl_HistStatsSettings?
    Google "multi-field primary key": I made one primary key from 4 fields in that table.

    Factor is a foreign key to ColName primary key. Factor is also "a part" of the primary key of the tbl_HistStatsSettings table. Stat is a foreign key to the StatName primary key.

    Does that change your reply?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I avoid compound primary keys. I would likely use an autonumber as PK and set the other 4 fields as compound index to prevent duplicate combinations.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    mountainclimber is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    56
    Quote Originally Posted by June7 View Post
    I avoid compound primary keys. I would likely use an autonumber as PK and set the other 4 fields as compound index to prevent duplicate combinations.
    Could you explain that a little more? I get the autonumber as pk. I've added that now. I've also added ID_FtrAggSttDays as the compound index. So then when I go to create the relationship I should use the autonumber pk?

    Edit: answered my own questions. Answer is yes. Thanks.
    Last edited by mountainclimber; 08-04-2015 at 10:34 AM. Reason: answered my own question

  6. #6
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Keep the relationships as they are, you will just have autonumber pk in your main table instead of the compound one.
    Keep the keys the same in the other tables.
    ColName(PK) -> Factor (FK, not a pk)
    StatName(PK) -> Stat (FK, not a pk)

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    1) To maintain name integrity: so the names can only be changed in one place and all names are found in any table can be found in tbl_NameDescs
    To have this, you must have a PK field that is related to a second table with a foreign (FK) field. The name is only stored in the primary table.


    2) To save space: I don't have to list the same name over and over again in the Factor field.
    Text type fields usually take up more space. So, again, if you have an autonumber PK field linked to a FK field, this takes less space that linking (relating) two text type fields.


    BTW, (it goes without saying - but I'm going to say it ) the linking fields, PK and FK, must be the same type of fields.

    It may be over kill, but I have a PK field (autonumber) in every table. Maybe it is not used, but if I ever need it, it is there - no table redesigns.

    I never use a compound PK field. It is better (easier) to use a compound index to eliminate duplicate records being entered.

    (Edit - Oops, I see that June already commented on the compound PK fields)


    Maybe these sites will help:
    Microsoft Access Tables: Primary Key Tips and Techniques
    http://www.fmsinc.com/free/newtips/primarykey.asp

    Autonumbers--What they are NOT and What They Are
    http://www.utteraccess.com/wiki/index.php/Autonumbers

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Doesn't hurt to hear (read) it again.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    mountainclimber is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    56
    Quote Originally Posted by ssanfu View Post
    To have this, you must have a PK field that is related to a second table with a foreign (FK) field. The name is only stored in the primary table.



    Text type fields usually take up more space. So, again, if you have an autonumber PK field linked to a FK field, this takes less space that linking (relating) two text type fields.


    BTW, (it goes without saying - but I'm going to say it ) the linking fields, PK and FK, must be the same type of fields.

    It may be over kill, but I have a PK field (autonumber) in every table. Maybe it is not used, but if I ever need it, it is there - no table redesigns.

    I never use a compound PK field. It is better (easier) to use a compound index to eliminate duplicate records being entered.

    (Edit - Oops, I see that June already commented on the compound PK fields)


    Maybe these sites will help:
    Microsoft Access Tables: Primary Key Tips and Techniques
    http://www.fmsinc.com/free/newtips/primarykey.asp

    Autonumbers--What they are NOT and What They Are
    http://www.utteraccess.com/wiki/index.php/Autonumbers

    I think I may do the same.... thx!

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

Similar Threads

  1. Replies: 3
    Last Post: 03-19-2015, 05:26 PM
  2. Replies: 1
    Last Post: 12-06-2014, 12:49 PM
  3. Relationship help
    By floyd in forum Database Design
    Replies: 9
    Last Post: 09-04-2013, 03:33 PM
  4. Help With One-to-many Relationship
    By Rick5150 in forum Forms
    Replies: 2
    Last Post: 02-24-2013, 01:20 PM
  5. Help with possible many-to-many relationship
    By gcw in forum Database Design
    Replies: 5
    Last Post: 02-21-2013, 07:14 PM

Tags for this Thread

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