Relationships between tables in Access

In this article, let’s learn about how to establish relationships with Quantrimang.com. Relationships is the relationship between two tables where a record in table A can have many matching records in table B and vice versa.

To create such a relationship, define a third table, called a junction table, whose primary key includes foreign keys from both table A and table B to split the relationship nn into two 1-n relationships .

Continuing with the examples in the previous tutorial, we add a table tblTacgia and a junction table tblTacgiaNoi. Board Author including fields TacgiaID, Ten, Ho, Diachi, Dienthoai, Email, Naysinh.

Add a new table tblTacgia with fields as shown
Add a new table tblTacgia with fields as shown

Often an author will work on multiple projects, just as a project can have multiple authors working on it. As in previous tutorials, the table tblDuAn There’s also an author field, so we’ll create a separate table that includes author information. So we don’t need this field in the table Project again.

The tblDuAn table also has a field about Author
The tblDuAn table also has a field about Author

Select field Tacgia, press the delete button and you will see the following message.

Delete the TacGia field on this board
Delete the TacGia field on this board

Click Yes.

Now we will create a junction table. This junction table has two foreign keys as follows:

Add 2 ID fields of two tables to this join table
Add 2 ID fields of two tables to this join table

These foreign key fields will be primary keys from the two tables tblTacgia and tblDuAn.

To generate keys for multiple in Access, select both of these fields, go to tab Thiết kế, click Primary Key, selected fields will all become keys.

The two selected schools both become keys
The two selected schools both become keys

Save the board with the name tblTacgiaNoi.

Next, go to Relationship in tab Thiết kế to create a relationship by clicking Show Table.

Add 3 tables tblDuAn, tblTacgia and tblTacgiaNoi
Add 3 tables tblDuAn, tblTacgia and tblTacgiaNoi

Select table tblDuAn, tblTacgia and tblTacgiaNoi, click Add to add all three panels to the desktop and then close the dialog Show Table.

See more:  How to see Liked Pages on Facebook
All 3 tables tblDuAn, tblTacgia and tblTacgiaNoi are added to the screen
All 3 tables tblDuAn, tblTacgia and tblTacgiaNoi are added to the screen

Use mouse to click and hold the field TacgiaID in the table tblTacgia, link to school TacgiaID you want to connect at the table tblTacgiaNoi. When you release the mouse, Access opens a window Edit Relationships. Note, the relationship that Access is creating will be treated as a 1-n relationship. You tick the box Cascade Update and click Create:

Dragging the two TacgiaID fields of the two tables together will display the Edit Relationships dialog box
Dragging the two TacgiaID fields of the two tables together will display the Edit Relationships dialog box

Result:

Result

Next, you drag the field DuAnID from the table tblDuAn go to school DuAnID board tblTacgiaNoi, check box Enforce Referential Integrity and Cascade Update Related Fields.

Drag the two DuAnID fields of the two tables together to display the Edit Relationships dialog box
Drag the two DuAnID fields of the two tables together to display the Edit Relationships dialog box

And this is the relationship we want to establish:

Relationships
Relationships

Previous article: 1-n relationships between tables in Access

Next article: Wildcard wildcard operator in Access

Source link: Relationships between tables in Access
– https://techtipsnreview.com/

, ,

Leave a Reply

Your email address will not be published. Required fields are marked *