Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforce Multiple Relationships Between Two Tables In Access

I want to create (and enforce) multiple "one-to-many" relationships between the primary key of one table to attributes of another.

Hopefully this example will explain better. I have a table for a character in a game. The character can hold one item in each hand.:

Table: GamePlayer
gamePlayerID    Number  PK
name            Text    Unique
classID         Number  FK->PlayerClass.classID
leftHandItem    Number  FK->Items.itemID
rightHandItem   Number  FK->Items.itemID

How do I implement the leftHandItem -> Items.itemID and rightHandItem -> Items.itemID with enforcing referential integrity.

like image 824
Steven Avatar asked Aug 02 '11 16:08

Steven


People also ask

How do you create multiple relationships in Access?

In the Relationships window, add the tables that you want to relate, and then drag the field to relate them from one table to the other table. Drag a field on to a table datasheet from the Field List pane.

How do you implement many-to-many relationships in Access?

To represent a many-tomany relationship, you must create a third table, often called a junction table, that breaks down the many-to-many relationship into two one-to-many relationships. To do so, we also need to add a junction table. Let us first add another table tblAuthers.

What do you need if you should enforce many-to-many relationship between two tables?

When you need to establish a many-to-many relationship between two or more tables, the simplest way is to use a Junction Table. A Junction table in a database, also referred to as a Bridge table or Associative Table, bridges the tables together by referencing the primary keys of each data table.


1 Answers

In the Relationships window, add the Items table twice. The second occurence will automatically get an alias. Use the 2 occurences like if they were 2 distinct tables to create relationships.

like image 94
iDevlop Avatar answered Sep 25 '22 15:09

iDevlop