Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Exploring Microsoft Office Access 2007 Chapter 7 Advanced Queries Robert Grauer, Keith Mulbery, Maurie Wigman Lockley Committed to Shaping the Next Generation of IT Experts.1 Copyright © 2008 Pearson Prentice Hall. All rights reserved. Objectives Maintain a database Understand action queries Create an Update query Use a make table query Create a delete query Copyright © 2008 Pearson Prentice Hall. All rights reserved. 2 Objectives Construct a crosstab query Work with parameter queries Create find unmatched queries Understand find duplicate queries Copyright © 2008 Pearson Prentice Hall. All rights reserved. 3 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 4 About Update Queries Changes value(s) in one/ more records Use the Update query button Update button Database Tools tab, Query Type group Copyright © 2008 Pearson Prentice Hall. All rights reserved. 5 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 Update value Value entered in Update To field Copyright © 2008 Pearson Prentice Hall. All rights reserved. 6 Testing Action Queries Check Datasheet View first Test all action queries before execution Choose Datasheet View Allows preview of results before execution Copyright © 2008 Pearson Prentice Hall. All rights reserved. 7 Running an Update Query Before Update query After Update query Click the Run button Run button Design tab, Results group View table to see the results Copyright © 2008 Pearson Prentice Hall. All rights reserved. 8 Specifying Criteria in an Action Query Criteria Specified in the field being update Also specified using an additional field(s) Copyright © 2008 Pearson Prentice Hall. All rights reserved. 9 Using Criteria with an Update Query Before update query with criteria Criteria After update query with criteria Specifies specific records for update Works the same as in a select query Copyright © 2008 Pearson Prentice Hall. All rights reserved. 10 About Append Queries Adds records from one table to another Data types between tables must match Validation rules in existing table apply Source table fields may be ignored Records not added if validation rule violated Do not add to design grid If auto-number fields exists in target table Do not import auto-number fields Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Creating an Append Query Append button Append dialog box Identify target and source tables Click Append button Choose Target table from Append box May also browse to choose another database Copyright © 2008 Pearson Prentice Hall. All rights reserved. 12 Creating an Append Query Fields to append added to design grid Add fields from Source table to design grid Test in Datasheet view Run query Copyright © 2008 Pearson Prentice Hall. All rights reserved. 13 Append Query Results February Agents after append February Agents before append September Agents before and after append Data is appended to existing table Copyright © 2008 Pearson Prentice Hall. All rights reserved. 14 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 15 Creating a Make Table Query Make Table button 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 16 Running a Make Table Query Fields added in design grid Test in Datasheet view Add fields to design grid Test in Datasheet view Run query Copyright © 2008 Pearson Prentice Hall. All rights reserved. 17 Make Table Query Results Source Table Results of make table query New table added to Objects pane Open table to view results Copyright © 2008 Pearson Prentice Hall. All rights reserved. 18 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 19 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 Delete Query with criteria Use criteria to specify delete conditions Copyright © 2008 Pearson Prentice Hall. All rights reserved. 20 Running a Delete Query Test in Design view Table before delete query Table after delete query Test query in Datasheet view Run Query Open table to view results Copyright © 2008 Pearson Prentice Hall. All rights reserved. 21 Hiding a Query All queries shown Some queries hidden Prevents accidental execution of action queries Right-click query Click the Hidden checkbox Copyright © 2008 Pearson Prentice Hall. All rights reserved. 22 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 23 Crosstab Query – Using the Query Wizard Step 1 Select Crosstab Query Wizard Click the Query Wizard button In the New Query dialog box Select Crosstab Query Wizard Copyright © 2008 Pearson Prentice Hall. All rights reserved. 24 Using the Query Wizard Step 2 Select source table or query to use Select table/query to use in crosstab To use fields from multiple tables Create query from tables first Copyright © 2008 Pearson Prentice Hall. All rights reserved. 25 Using the Query Wizard Step 3 Select field(s) for column headings Select fields(s) for column headings Copyright © 2008 Pearson Prentice Hall. All rights reserved. 26 Using the Query Wizard Step 4 Select aggregate function Select the field to calculate Select the appropriate aggregate function Copyright © 2008 Pearson Prentice Hall. All rights reserved. 27 Using the Query Wizard Step 5 Enter new name or accept default name Enter new query name or accept default View or modify the query Copyright © 2008 Pearson Prentice Hall. All rights reserved. 28 Completed Crosstab Query Source table Crosstab query Summarizes list price Per selling/listing agent per city Copyright © 2008 Pearson Prentice Hall. All rights reserved. 29 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 30 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 31 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 32 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 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 33 About Unmatched Queries Unmatched Query results Compares records in two related tables Returns records found in only one table Query Wizard easiest method of creation Copyright © 2008 Pearson Prentice Hall. All rights reserved. 34 Unmatched Query Wizard Find Unmatched Query Run Query Wizard Select Find Unmatched Query Wizard Copyright © 2008 Pearson Prentice Hall. All rights reserved. 35 Unmatched Query Wizard Select first table source Select first table source Select second table source Select second table source Copyright © 2008 Pearson Prentice Hall. All rights reserved. 36 Unmatched Query Wizard Select duplicate fields Select the duplicate fields Click the <=> button Select display fields for query results Click Finish Select fields for query results Copyright © 2008 Pearson Prentice Hall. All rights reserved. 37 About Find Duplicates Query Query Wizard Find Duplicates query result Finds duplicate data Aids in data entry error detection Allows administrative use of purposely duplicated data Easily created with the Query Wizard Copyright © 2008 Pearson Prentice Hall. All rights reserved. 38 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 39