如何在 Access 2016 中创建查询和表之间的一对多关系? [英] How to create a one-to-many relationship between a query and a table in Access 2016?

查看:144
本文介绍了如何在 Access 2016 中创建查询和表之间的一对多关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上面是人"表

以上是基于People"表查询Count Country"的SQL视图

Above is the SQL view of the Query "Count Country" based on Table "People"

以上是基于表People"的查询Count Country"的数据表视图

Above is the datasheet view of the Query "Count Country" based on Table "People"

上面是另一个名为城市列表"的表格

Above is another Table called "City List"

为什么我不能在查询Count Country"和表City List"之间创建一对多关系?

Why can't I create a one-to-many relationship between Query "Count Country" and Table "City List"?

推荐答案

您只能在表之间创建具有参照完整性的关系.此外,两个字段必须具有相同的数据类型,并且左侧的字段(您拖到另一侧的字段)必须是该表的主键(或至少有一个唯一索引)不允许使用 Null 值).

You can only create a relationship with referential integrity between tables. Also, both fields must have the same data type and the field(s) on the left (the field(s) that you draggeed to the other side) must be the primary key of that table (or at least have a unique index that does not allow for Null values).

创建没有参照完整性的关系的唯一原因是告诉 Access 数据是如何相关的,因此当您将这两个表都添加到一个表中时,Access 将自动连接这两个表(或者在您的情况下是表和查询)询问.此外,Access 可能会在处理数据表时自动创建子数据表".

The only reason for creating a relationship without referential integrity is to tell Access how the data is related, so Access will join both tables (or as in your case the table and the query) automatically when you add both of them to a query. Also, Access might automatically create a "subdatasheet" when dealing with datasheets.

要自动"构建跳转到城市的表单,请使用表单向导并从查询和表中添加字段.

To "automatically" build the form that jumps to the cities, use the form wizard and add fields from both your query and your table.

这篇关于如何在 Access 2016 中创建查询和表之间的一对多关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆