Results 1 to 10 of 10
  1. #1
    acannon is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Birmingham, AL
    Posts
    16

    Smile Referential Integrity With Compound Index

    Can I use a compound index to enforce referential integrity between tables? If that works can I use cascade update/delete? If that isn't possible I would use an autonumber field in the primary table, but how would I relate records to the subsidiary tables?



    I have 12 subsidiary tables to relate to 1 primary table.

    I appreciate any and all comments and suggestions!

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Can I use a compound index to enforce referential integrity between tables?
    No.
    Indexes (indexing) make it faster to find data in a field that is indexed compared to a non-indexed field. You can use multi-field indexes to make it faster to find records that have the data specified in the fields. You can also use multi-field indexes to limit duplicated data (ie create unique records) in the indexed fields.

    It sounds like you are thinking about a multi-field primary key. IMO, this is usually not required.
    I always use autonumber type fields for my PK fields. So much easier.

    If that isn't possible I would use an autonumber field in the primary table, but how would I relate records to the subsidiary tables?
    The autonumber PK field is related to a FK field in another table. Cascade updates/deletes work (but I would use them sparingly).


    Can you explain what you are attempting to do? Some background on you r dB?

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    @acannon
    Are you thinking about a compound key? Maybe you can. I don't use the relationships window so I don't know.

  4. #4
    ButtonMoon is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2013
    Posts
    17
    Can I use a compound index to enforce referential integrity between tables? If that works can I use cascade update/delete?
    The answer to both questions is yes. A foreign key can reference any key (in fact any unique index) in the parent table. The unique key being referenced can be a composite of several columns and it doesn't have to be the "primary" key.

    Typically you should try to choose keys that are simple and stable (i.e. unlikely that key values will change). Your keys should also be non-nullable. Unique indexes on nullable columns are not such a good idea and personally I would strongly recommend you avoid them. More often than not it's a good idea for foreign keys to reference just a single attribute (i.e. a "simple" key) but that isn't an absolute rule.

  5. #5
    acannon is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Birmingham, AL
    Posts
    16
    Thanks for the response! In answer to the request of background info and what I'm trying to do, please see my perhaps incoherent rambling below.

    This is a multi-functional Project Equipment Management System for engineering projects. We will have a separate db for each project. Each item of equipment is identified by an equipment number of the form AAA-TTT-SSSS.DD. Each element of the number is stored in a separate field in the master table. The length of AAA and TTT are variable, and they are text fields to accept alphanumeric data. SSSS is a numeric value of up to 4 digits and DD is a 2-digit numeric decimal value to identify separate components of the base SSSS number. Every item of equipment has a record in the master table. The related tables contain specific details about each item of equipment, and the details vary with the type of equipment, which is designated by the TTT field. Some types have only 4 general text fields to provide details and some have numerous text and numeric fields to provide the details. The combination of the AAA field and the SSSS.DD field must be unique although each may be used multiple times individually.

    Currently I am using VBA in the data entry forms to create a record in the appropriate related table using the AAA and SSSS.DD fields entered in the master table data entry form for new items of equipment. I am using the 2 fields as a compound unique index to prevent duplication.

    As a project progresses a piece of equipment may be deleted. For historical purposes we don't actually delete the record; we simply add "D" to the end of the AAA field and then the normal routine of the db application filters those out of the ongoing work. What I want to do is to make that change in the master table and have it cascade to the appropriate related table. Currently it must be changed in the related tables. There are additional related tables for tracking the purchasing, specification, shipping status, etc, which also need to be cascade updated, although those functions have not yet been developed. If I can get the referential integrity and cascade update working then I won't have to right additional code to handle the process.

    Thanks for the interest.

    Alan

  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,726
    Please tell us about your tables and relationships.
    Can you post a jpg of your relationships window?

    Have you tested your data model with some sample data and scenarios?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I avoid compound keys as much as possible. I would prefer to use autonumber as the key. Can still set the multiple fields as a compound index to prevent duplicate combinations.

    Generating custom unique identifier is a common topic.

    If you want to use that value for sorting, be aware that numbers will be subject to alpha sort rules. So 101 will sort before 20. Need placeholder zeros. So 0101 will sort after 0020.
    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.

  8. #8
    ButtonMoon is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2013
    Posts
    17
    acannon,
    Sounds fine so far, but what is your question? To enable cascading updates using a composite unique key just select the "Enforce Referential Integrity" and "Cascade Update Related Fields" options.

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have 12 subsidiary tables to relate to 1 primary table.
    OK, this is how I would structure the main table

    Main Table
    ------------
    MainID_PK Autonumber (PK)
    txtAAA Text
    txtTTT Text
    intSSSS Integer
    intDD Integer
    bolDeleted Yes/No (boolean)
    ...other fields....

    I added the field "bolDeleted"; really shouldn't have one field for two items (part of the equipment number and if it is deleted - this violates normalization rules).

    I would set a multi-field index using the fields "txtAAA, txtTTT, intSSSS, intDD" set to "INDEXED NO DUPLICATES".

    The 12 subsidiary tables would be related to the Master table using MainID_PK. I usually name the foreign key field like "MainID_FK". No need for cascading updates.

    As orange requested, I also would like to see a jpg of your relationships window to have a better understanding of your tables/relationships.

  10. #10
    acannon is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Birmingham, AL
    Posts
    16
    My problem has been solved. The dual-key relationship worked exactly as needed, including the cascade update and delete.

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

Similar Threads

  1. Referential Integrity
    By YunqHero in forum Forms
    Replies: 4
    Last Post: 12-17-2012, 05:05 PM
  2. Referential Integrity
    By Paul H in forum Database Design
    Replies: 3
    Last Post: 11-14-2011, 03:07 PM
  3. referential integrity
    By askjacq in forum Database Design
    Replies: 1
    Last Post: 10-14-2011, 03:23 PM
  4. Referential Integrity
    By Desstro in forum Database Design
    Replies: 4
    Last Post: 06-13-2010, 01:29 PM
  5. Referential Integrity
    By U810190 in forum Access
    Replies: 1
    Last Post: 03-29-2010, 05:21 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