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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With