Ms Access 简明教程

MS Access - Action Queries

在 MS Access 和其他 DBMS 系统中,查询不仅可以显示数据,还可以针对数据库中的数据执行各种操作。

In MS Access and other DBMS systems, queries can do a lot more than just displaying data, but they can actually perform various actions on the data in your database.

  1. Action queries are queries that can add, change, or delete multiple records at one time.

  2. The added benefit is that you can preview the query results in Access before you run it.

  3. Microsoft Access provides 4 different types of Action Queries − Append Update Delete Make-table

  4. An action query cannot be undone. You should consider making a backup of any tables that you will update by using an update query.

Create an Append Query

您可以使用附加查询从一个或多个表中检索数据,并将该数据添加到另一个表中。让我们创建一个新表,其中我们将从 tblEmployees 表中添加数据。这将是用于演示目的的临时表。

You can use an Append Query to retrieve data from one or more tables and add that data to another table. Let us create a new table in which we will add data from the tblEmployees table. This will be temporary table for demo purpose.

让我们称之为 TempEmployees ,其中包含如下图所示的字段。

Let us call it TempEmployees and this contains the fields as shown in the following screenshot.

tempemployees
tempemployees table

Tables 选项卡上的“显示表”对话框中,双击 tblEmployees 表,然后关闭对话框。双击您要显示的字段。

In the Tables tab, on the Show Table dialog box, double-click on the tblEmployees table and then close the dialog box. Double-click on the field you want to be displayed.

table dialog box

让我们先运行您的查询来显示数据。

Let us run your query to display the data first.

data first

现在让我们回到查询设计并选择 Append 按钮。

Now let us go back to Query design and select the Append button.

append

在“查询类型”中,选择“附加”选项按钮。这将显示以下对话框。

In the Query Type, select the Append option button. This will display the following dialog box.

append table name

从下拉列表中选择表名,然后单击确定。

Select the table name from the drop-down list and click Ok.

query1

在查询网格中,您可以在 Append To 行中看到默认情况下所有字段都被选中,除了 Address1 。这是因为 TempEmployee 表中没有 Address1 字段。因此,我们需要从下拉列表中选择字段。

In the Query grid, you can see that in the Append To row all the field are selected by default except Address1. This because that Address1 field is not available in the TempEmployee table. So, we need to select the field from the drop-down list.

appendto

我们来看一下 Address 字段。

Let us look into the Address field.

address field

现在让我们运行您的查询,您将看到以下确认消息。

Let us now run your query and you will see the following confirmation message.

confirmation message

单击 Yes 以确认您的操作。

Click Yes to confirm your action.

data added

当您打开 TempEmployee 表时,您将看到 tblEmployees 中的所有数据都被添加到 TempEmployee 表中。

When you open the TempEmployee table, you will see all the data is added from the tblEmployees to the TempEmployee table.