Ms Access 简明教程

MS Access - Create Queries

让我们了解在本节中如何创建查询。

Let us understand how to create queries in this chapter.

Create an Update Query

您可以使用更新查询来更改表中的数据,并且可以使用更新查询输入条件以指定应更新哪些行。更新查询为您提供了一个机会,让您在执行更新操作之前检查更新后的数据。我们再次转到“创建”选项卡,然后单击查询设计。

You can use an Update Query to change the data in your tables, and you can use an update query to enter criteria to specify which rows should be updated. An update query provides you an opportunity to review the updated data before you perform the update. Let us go to the Create tab again and click Query Design.

query design

在“表”选项卡上的“显示表”对话框中,双击 tblEmployees 表,然后关闭对话框。

In the Tables tab, on the Show Table dialog box, double-click on the tblEmployees table and then close the dialog box.

close dialog box

Design 选项卡上的“查询类型”组中,单击更新并在其中更新值的字段上双击。让我们说我们想将 “Rex” 的 FirstName 更新为 “Max”。

On the Design tab, in the Query Type group, click Update and double-click on the field in which you want to update the value. Let us say we want to update the FirstName of “Rex” to “Max”.

design tab max

UpdateDesign 网格中,输入更新的值,在条件行中添加想要更新的原始值,并运行查询。这将显示确认信息。

In the Update row of the Design grid, enter the updated value and in Criteria row add the original value which you want to be updated and run the query. This will display the confirmation message.

update records

单击 Yes 并转到数据表视图,您将看到第一条记录 — FirstName 现已更新为“Max”。

Click Yes and go to Datasheet View and you will see the first record — FirstName is updated to “Max” now.

first record

Create a Delete Query

您可以使用删除查询从表格中删除数据,并且可以使用删除查询输入条件来指定应删除哪些行。删除查询为您提供了机会来检查在执行删除之前将要删除的行。让我们再次转到 Create 选项卡,然后单击 Query Design

You can use a delete query to delete data from your tables, and you can use a delete query to enter criteria to specify which rows should be deleted. A Delete Query provides you an opportunity to review the rows that will be deleted before you perform the deletion. Let us go to the Create tab again and click Query Design.

query design

在“显示表”对话框的“表格”选项卡上,双击 tblEmployees 表,然后关闭此对话框。

In the Tables tab on the Show Table dialog box, double-click the tblEmployees table and then close the dialog box.

property sheet

Design 选项卡的 Query Type 组中,单击 Delete 并双击 EmployeeID

On the Design tab, in the Query Type group, click Delete and double-click on the EmployeeID.

employee id

在设计网格的条件行中,输入 11。在这里,我们想要删除 EmployeeID 为 11 的员工。

In the Criteria row of the Design Grid, type 11. Here we want to delete an employee whose EmployeeID is 11.

description

现在,我们运行查询。此查询将显示确认信息。

Let us now run the query. This query will display the confirmation message.

display query

单击 Yes 并转到数据表视图,您将看到指定的员工记录现已删除。

Click Yes and go to your Datasheet View and you will see that the specified employee record is deleted now.

specified record

Create a Make Table Query

您可以使用制作表格查询根据存储在其他表格中的数据创建新表格。让我们再次转到 Create tab 并单击 Query Design

You can use a make-table query to create a new table from data that is stored in other tables. Let us go to the Create tab again and click Query Design.

query design

在“表格”选项卡,“显示表”对话框上,双击 tblEmployees 表,然后关闭此对话框。

In the Tables tab, on the Show Table dialog box, double-click the tblEmployees table and then close the dialog box.

make table

选择所有想要复制到其他表格的字段。

Select all those fields which you want to copy to another table.

another table

在查询类型中,选择 Make Table 选项按钮。

In the Query Type, select the Make Table option button.

make table button

您将看到以下对话框。输入您想要创建的新表格的名称,然后单击“确定”。

You will see the following dialog box. Enter the name of the new table you want to create and click OK.

enter new table

现在运行您的查询。

Now run your query.

run your query

您现在将看到以下消息。

You will now see the following message.

undo command

单击 Yes ,您将看到导航窗格中创建了一个新表。

Click Yes and you will see a new table created in the navigation pane.

created new table