Ms Access 简明教程

MS Access - Create Relationships

在本章中,我们将了解创建相关表之间关系的必要性。良好的数据库设计目标之一是消除数据冗余。

In this chapter, we will understand the need to create relationships between related tables. One of the goals of good database design is to remove data redundancy.

  1. To achieve that goal, you divide your data into many subject-based tables so that each fact is represented only once.

  2. To do this, all the common fields which are related to each other are placed in one table.

  3. To do this step correctly, you must first understand the relationship between your tables, and then specify these relationships in your Access database.

Why Create Table Relationships?

当您需要在数据库对象中使用表时,MS Access 使用表关系连接表。在创建其他数据库对象(例如窗体、查询、宏和报表)之前,您应该创建表关系的原因有多个。

MS Access uses table relationships to join tables when you need to use them in a database object. There are several reasons why you should create table relationships before you create other database objects, such as forms, queries, macros, and reports.

  1. To work with records from more than one table, you often must create a query that joins the tables.

  2. The query works by matching the values in the primary key field of the first table with a foreign key field in the second table.

  3. When you design a form or report, MS Access uses the information it gathers from the table relationships you have already defined to present you with informed choices and to prepopulate property settings with appropriate default values.

  4. When you design a database, you divide your information into tables, each of which has a primary key and then add foreign keys to related tables that reference those primary keys.

  5. These foreign key-primary key pairings form the basis for table relationships and multi-table queries.

现在,让我们使用表设计在您的数据库中添加另一个表,并将其命名为 tblHRData ,如下面的屏幕截图所示。

Let us now add another table into your database and name it tblHRData using Table Design as shown in the following screenshot.

table design

单击 Save 图标,如上面的屏幕截图所示。

Click on the Save icon as in the above screenshot.

save icon

输入 tblHRData 作为表名,然后单击 Ok

Enter tblHRData as table name and click Ok.

tblhrdata

tblHRData 现在已创建并包含数据。

tblHRData is now created with data in it.