Solved How to connect two primary keys (1 Viewer)

cheberdy

Member
Local time
Today, 08:27
Joined
Mar 22, 2023
Messages
77
If I have a master table where I have "Autotypes" as primary key and I have a second table with the primary key colors "Colors". I want that an autotype never has a duplicate color, but two different autotypes can have the same color. How do I get this to work?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:27
Joined
May 7, 2009
Messages
19,243
you add another field (long integer) to your second table.
this will serve as it's Foreign Key (refering to your first table, pointing to it's Autotype field.).

the New field should write the Autotype value of the first table.

create a relationship between your tables.
 

cheberdy

Member
Local time
Today, 08:27
Joined
Mar 22, 2023
Messages
77
If I have a master table where I have "Autotypes" as primary key and I have a second table with the primary key colors "Colors". I want that an autotype never has a duplicate color, but two different autotypes can have the same color. How do I get this to work?
Sorry I forgot, it should then produce all possible records
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:27
Joined
Feb 19, 2002
Messages
43,275
The autotype table needs a FK to the color table. Since there is only one column for color for an autotype, it is not possible for the autotype to have multiple colors. But colors can be used on multiple autotypes. You would NOT add an index to the new color column. If you create the relationship using the Relationship window, Access will automagically create a HIDDEN index on the foreign key.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:27
Joined
Feb 19, 2002
Messages
43,275
@cheberdy When you mark a thread solved, it is helpful to identify a specific post that solved the problem if there is just one. Otherwise, just describe your solution. This makes the thread very valuable when other searchers find it. Just marking this post solved will discourage additional posts but it doesn't help anyone who comes across this later.
 

Users who are viewing this thread

Top Bottom