Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513

    relationships 101

    this really is a 101,
    (and also that area that 'with some minor embarrassment) I've never been able to get right)

    relating 2 tables...
    the primary (1`) table (tblManufacturerRepAgencies) is the "one" side
    the secondary (2`) table(tblManufacturers) is the "many" side

    for the related field (RepAgency)
    ...in the 2`table, whenever the field has a value, it will always also exist in the 1`table;
    2` table it will not always have a value in that field; it may be null.

    i need to enforce referential integrity so that when a record in 1`is changed, the change also occurs in 2`



    i ran a query to find any records in 2` that had a field value that was not in 1` and have corrected all errors;
    the only records in 2` that do not have a match in 1` are blank (in the related field)

    yet when i set up the relationship

    Include ALL records from 'tblManufacturerRepAgencies'
    and only those records from 'tblManufacturers' where the joined fields are equal.

    and then check enforce... cascade update
    ...I get the usual: "can't do"


    utterly stumped
    with appreciation in advance,
    m.

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I have an extended article about relationships and referential integrity on my website which may help you get out of room 101
    See http://www.mendipdatasystems.co.uk/r...ps1/4594533224

    HTH
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I'll take a stab at this. I can tell you how I design and relate tables.

    This is for a 1-to many relationship. To have RI, the linking fields must be the same data type. This means that you cannot have one field as a text type and the other field as a long integer.
    And the "1" table field must be unique.

    In my tables I always (99.8%) have the PK field as an Autonumber type. This means the linking field in the "many" table must be a long integer. Also, because I use an Autonumber type in the "1" table, the linking field in the "many" table can never be 0 or NULL.

    When I name fields in tables, the PK field, because it is a number field (autonumber), I use a suffix of "ID_PK". For the linking field in the "many" table, I use a suffix of "ID_FK". Some may say that the "ID_" is not necessary and they would be correct. But this is how I nave decided to name fields. I do not have any field with the same name in any other table and it is easier to know which fields I am working with, especially when setting the links in Main form/sub form designs or in code.

    Speaking of Main form/sub form (and report) designs, because the sub form is linked to the main form, the sub form linking field value is automatically entered when a new record is created in the sub form. If you execute update queries or append queries in code, you are responsible to enter the correct value into the "many" linking field.


    So, the 1 table is "tblManufacturerRepAgencies". I would set the PK field type to Autonumber and name it "ManRepAgencyID_PK".
    The many table, "tblManufacturers", I would set the PK field type to Autonumber and name it "ManufactureID_PK".
    The linking field (to table "tblManufacturerRepAgencies") would be type Long and I would name it "ManRepAgencyID_FK".

    I would add the two tables to the Relationship window and drag "ManRepAgencyID_PK" to "ManRepAgencyID_FK". If there are no NULLs, no zeros and any value in "ManRepAgencyID_FK" is in "ManRepAgencyID_PK", a link will be created. The 1 side will have a "1" next to the PK field and the many side will have the infinity symbol next to the FK field.



    You might also see Microsoft Access Tables: Primary Key Tips and Techniques



    Or just read Colin's site.......


  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

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

Similar Threads

  1. Help with Relationships
    By Gregm66 in forum Access
    Replies: 2
    Last Post: 09-10-2016, 02:27 PM
  2. Replies: 7
    Last Post: 08-05-2016, 11:53 AM
  3. Replies: 2
    Last Post: 07-27-2016, 10:25 AM
  4. Explicit Relationships and Implicit Relationships
    By Dazza666 in forum Database Design
    Replies: 2
    Last Post: 07-17-2013, 02:11 AM
  5. Relationships
    By snowboarder234 in forum Database Design
    Replies: 14
    Last Post: 02-29-2012, 04:53 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