Download presentation
Presentation is loading. Please wait.
1
Exploring Microsoft Office Access 2010
Chapter 7 Action Queries This chapter’s focus is on the use of advanced queries in Access. 1 1
2
Objectives Maintain a database Understand action queries
Create an Update query Create an Append query Use a make table query Create a delete query The objectives of this chapter are: Maintain a database Understand action queries Create an Update query Use a make table query Create a delete query
3
Objectives Construct a crosstab query Work with parameter queries
Create find unmatched queries Understand find duplicate queries Additional objectives of this chapter are: Construct a crosstab query Work with parameter queries Create find unmatched queries Understand find duplicate queries
4
Action Queries Change underlying table data
Select queried do not Can be used to create new tables Cannot be undone Play a large role in maintaining a database Action queries change underlying table data; select queries do not. Action queries cannot be undone. They play a large role in maintaining a database.
5
About Update Queries Changes value(s) in one/ more records
Use the Update query button Database Tools tab, Query Type group Update button Update queries changes the value in one or more records. They can update all records when a new field is created, change the value in existing records, and may or may not be used with criteria. To begin an update query, use the Update query button located on the Database Tools tab in the Query Type group.
6
Creating an Update query
Identify record source Show desired tables in design grid Switch from Select to Update Query Insert Field to be updated Enter the value to be updated Value entered in Update To field Update value To create an update query, enter the value you wish to update in the Update To field in the query grid.
7
Testing Action Queries
Check Datasheet View first Test all action queries before execution. To do this, choose Datasheet View after all criteria has been entered. This allows you to preview results before execution. Remember that action queries cannot be undone. Test all action queries before execution Choose Datasheet View Allows preview of results before execution
8
Running an Update Query
Before Update query After Update query To run an update query, click the run button located in the Design tab, results group. Switch to the table you were updating to view the results. Run button Click the Run button Design tab, Results group View table to see the results
9
Specifying Criteria in an Action Query
You can specify certain records to be updated by using criteria in action queries. Criteria may be specified in the field being updated as well as additional field(s). Specified in the field being update Also specified using an additional field(s)
10
Using Criteria with an Update Query
Before update query with criteria Criteria Rules and methods for using criteria to select specific records for update in an action query are the same as when criteria is used in basic select queries. After update query with criteria Specifies specific records for update Works the same as in a select query
11
Copyright © 2008 Pearson Prentice Hall. All rights reserved.
About Append Queries Adds records from one table to another Data types between tables must match Validation rules in existing table apply Records not added if validation rule violated Source table fields may be ignored Do not add to design grid If auto-number fields exists in target table Do not import auto-number fields Append queries add records from one table to another. Data types between the tables you are working with must match. The validation rules that are in the existing table apply. If validation rules are violated, records will not be not added to the table. You may choose fields form the source table to be ignored during the import if necessary. This is accomplished by not adding the field(s) to the design grid. If auto-number fields exists in target table, do not import auto-number fields from target. Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11
12
Creating an Append Query
Append button Append dialog box To create an append query, first identify target and source tables. Click the Append button. Choose Target table from Append box (you may also browse to choose a table in another database). Identify target and source tables Click Append button Choose Target table from Append box May also browse to choose another database
13
Creating an Append Query
Fields to append added to design grid Add the fields from the source table to the design grid. Test in Datasheet view, then run the query. Add fields from Source table to design grid Test in Datasheet view Run query
14
Append Query Results Data is appended to existing table
February Agents after append February Agents before append The final result will show that the data is appended to the existing table. September Agents before and after append Data is appended to existing table
15
About a Make Table Query
Almost the same as append query Table must preexist in append query No pre-existing table in make table query Target database must exist A Make Table query is almost the same as an append query. The difference is that in an append query, the table must preexist. In a make table query, the target database must preexist.
16
Creating a Make Table Query
Make Table button Make Table dialog box In order to create a make table query, first identify the source table and then click Make Table button. Enter a table name or choose the database. This is accomplished in the Make table dialog box. Identify the source table Click Make Table button Enter table name or choose database Accomplished in the Make table dialog box
17
Running a Make Table Query
Fields added in design grid Test in Datasheet view Next, add fields to the design grid. Test in Datasheet view and run the query. Add fields to design grid Test in Datasheet view Run query
18
Make Table Query Results
Source Table Results of make table query The final results yield a new table added to the Objects pane. Open the table to view the results. New table added to Objects pane Open table to view results
19
About Delete Queries Can delete all records from table
Criteria used to delete specific records If no criteria, all records deleted Very powerful – cannot be undone Setup is same as other action queries Delete queries can delete all records from a table, or, if criteria is used, delete specific records from a table. If no criteria is used, all records are deleted. This is a very powerful query– it cannot be undone. Initial setup is the same as other action queries.
20
Creating a Delete Query
Add table to design grid Delete button Add table to Design grid Click Delete Button Add field(s) to design grid Use criteria to specify delete conditions To create a delete query, first add a table to the Design grid. Then click the Delete Button and add field(s) to the design grid. Use criteria to specify the delete conditions. Delete Query with criteria
21
Running a Delete Query Test query in Datasheet view Run Query
Test in Design view Table before delete query Table after delete query Test the query in Datasheet view. Run the query and open a table to view results. Test query in Datasheet view Run Query Open table to view results 21
22
Hiding a Query Prevents accidental execution of action queries
All queries shown Some queries hidden Hiding a query prevents accidental execution of action queries. To hide a query, right-click the query and click the Hidden checkbox. Prevents accidental execution of action queries Right-click query Click the Hidden checkbox
23
UPDATE Data Field: Using SQL view UPDATE Product SET UnitPrice = [UnitPrice] *[UnitPrice]
24
About Crosstab Queries
Summarizes by two sets of unrelated facts Output resembles a PivotTable PivotTable primarily for management decision making Crosstab query primarily for end users Will not work on related data Works with one or more tables Crosstab queries summarize values by two sets of unrelated facts. The output resembles a PivotTable; however, a PivotTable is primarily for management decision making. Crosstab queries are primarily for end users. Crosstab queries will not work on related data. They will work with one or more tables. 24
25
Crosstab Query – Using the Query Wizard Step 1
Select Crosstab Query Wizard To begin a crosstab query, click the Query Wizard button. In the New Query dialog box, select Crosstab Query Wizard. Click the Query Wizard button In the New Query dialog box Select Crosstab Query Wizard 25
26
Using the Query Wizard Step 2
Select source table or query to use Select the table/query to use in the crosstab. To use fields from multiple tables, first create a query. Use that query as the table for the crosstab Select table/query to use in crosstab To use fields from multiple tables Create query from tables first 26
27
Using the Query Wizard Step 3
Select field(s) for column headings Select the field(s) to be used for column headings. Select fields(s) for column headings 27
28
Using the Query Wizard Step 4
Select aggregate function Select the field you would like to calculate, then select the appropriate aggregate function. Select the field to calculate Select the appropriate aggregate function 28
29
Using the Query Wizard Step 5
Enter new name or accept default name Enter a new query name or accept the default name. View or modify the query. Enter new query name or accept default View or modify the query
30
Completed Crosstab Query
Source table Crosstab query This is a completed crosstab query. Summarizes list price Per selling/listing agent per city
31
About Parameter Queries
Information intentionally omitted by designer Allows end user to supply criteria Customizable data request More flexible than other query types Considered a select query Designers able to lock query design Parameter queries consist of information intentionally omitted by the designer. This allows the end user to supply criteria. It provides for customizable data request and is more flexible than any other query type. Parameter queries are considered to be select queries and are not action queries. This type of query also allows the query designer to lock down the query design.
32
Creating a Parameter Query
Message for user entered in brackets Identify tables/ fields in design view Create prompt for user in criteria field Prompt must be enclosed in brackets [ ] Multiple fields can be used as prompts To create a parameter query, first identify the necessary tables and fields in design view. Create a prompt for the user in the criteria field. The prompt must be enclosed in brackets [ ]. You can create prompts for multiple fields.
33
Running a Parameter Query
Message prompt with criteria entered Parameter query results Click the Run button Enter criteria in message box Criteria rules and use is same as normal select query View results in Datasheet view Click the Run button. Enter criteria in the message box then view the results in Datasheet view.
34
Parameter Report Normally based of a parameter query
If not based on parameter query Open reports source query in design view Add parameter Or View report in Design Open property sheet for field Click Record Source property - add parameter Parameter reports are normally based off a parameter query. If not based on a parameter query, a parameter report can be created by following the steps below: 1. Open reports source query in design view 2.Add the parameter OR 1. View the report in Design view 2. Open the property sheet for the field 3. Click the Record Source property and add the parameter
35
About Unmatched Queries
Unmatched Query results Unmatched queries compares records in two related tables. It returns records found in only one table – not both. The Query Wizard is the easiest method of creation. Compares records in two related tables Returns records found in only one table Query Wizard easiest method of creation
36
Unmatched Query Wizard
Find Unmatched Query To begin an unmatched query, run the Query Wizard and select Find Unmatched Query Wizard in the New Query dialog box. Run Query Wizard Select Find Unmatched Query Wizard
37
Unmatched Query Wizard
Select first table source Select first table source Select second table source In the next dialog box, select the first table source. Click Next. Select the second table source and click Next. Select second table source
38
Unmatched Query Wizard
Select duplicate fields Select the duplicate fields Click the <=> button Select display fields for query results Click Finish In the next dialog boxes, you will Select the duplicate fields and click the <=> button. Proceed to the next dialog box and select display fields for the query results. Click Finish. Select fields for query results
39
About Find Duplicates Query
Query Wizard Find Duplicates query result Find Duplicate queries find duplicate data and aid in data entry error detection. They also allow administrative use of purposely duplicated data. Find duplicate queries are easily created with the Query Wizard. Finds duplicate data Aids in data entry error detection Allows administrative use of purposely duplicated data Easily created with the Query Wizard
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.