ACC: Can't Create Relationship with Multiple-Field Primary Key

Last reviewed: May 14, 1997
Article ID: Q155514
The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97

SYMPTOMS

Novice: Requires knowledge of the user interface on single-user computers.

When you try to create a relationship that enforces referential integrity, and the relationship involves a multiple-field primary key, you may receive the following error:

In Microsoft Access 7.0 and 97

   No unique index found for referenced field of primary table.

In Microsoft Access 2.0

   Can't create relationship to enforce referential integrity. The
   field(s) in the primary table must be the primary key or have a
   unique index.

CAUSE

The order of the primary key fields in Design view of the table is different from the order of the fields in the PrimaryKey index.

RESOLUTION

There are two ways to work around this error:

  1. Reorder the PrimaryKey fields in the index so that they appear in the same order as they do in Design view of the table.

  2. Order the field names in the Relationships dialog box to match the order of the field names in the PrimaryKey index.

STATUS

Microsoft has confirmed this to be a problem in Microsoft Access 2.0, 7.0, and 97. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Problem

Creating the Tables

  1. Create a new table in Design view.

  2. Add the following fields to the table:

    Table: ------------------ Field Name: A

             Data Type: Text
          Field Name: B
             Data Type: Text
    
    

  3. Highlight both fields by holding down the SHIFT key while you click the row selector button to the left of each field name, and then release the SHIFT key.

  4. On the Edit menu, click Primary Key (or Set Primary Key in version 2.0).

  5. On the View menu, click Indexes.

  6. Change the order of the fields in the PrimaryKey index so that B is in the first row, and A is in the second row:

          Index Name   Field Name   Sort Order
          ------------------------------------
          PrimaryKey   B            Ascending
                       A            Ascending
    
    

  7. Close the Indexes dialog box.

  8. Save the table as tblOne and close it.

  9. Repeat steps 1 and 2.

  10. Save the table as tblTwo and close it. You do not need to create a primary key index on this table.

Creating the Relationships

  1. Open the Relationships window by clicking Relationships on the Tools

        menu (or in version 2.0, click Relationships on the Edit menu.)
    

  2. On the Relationships menu, click Show Table (or Add Table in version 2.0). Add the tblOne table and the tblTwo table to the Relationships window.

  3. Highlight fields A and B in the tblOne table by holding down the SHIFT key while you click both fields, and then release the SHIFT key.

  4. Drag the highlighted fields A and B from the tblOne table to the tblTwo table to invoke the Relationships dialog box.

  5. Select fields A and B from the tblTwo table in the Related Table/Query column, so that the Relationships dialog box looks as follows:

          Table/Query: tblOne   Related Table/Query: tblTwo
          -------------------------------------------------
                   A                       A
                   B                       B
    
    

  6. Click Enforce Referential Integrity.

  7. Click the Create button. Note that the error message appears.

  8. Click Cancel in the Relationships dialog box, and then close the Relationships window. You do not need to save your changes.

REFERENCES

For more information about using a multiple field primary key, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q98793
   TITLE     : ACC: Compound Indexes Must Restrict First Indexed Field

For more information about enforcing referential integrity, type "What is Referential Integrity" in the Office Assistant, click Search, and then click to view "What is Referential Integrity?"


Additional query words: index multiple field primary key
Keywords : kberrmsg kbusage RltRef
Version : 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbbug
Resolution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 14, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.