8/7/2019 3. Maintaining and Querying a Database
1/29
Maintaining andQuerying a Database
8/7/2019 3. Maintaining and Querying a Database
2/29
XP
Objectives
2
y Find, modify, and delete records in a table
y Learn how to use the Query window in Design view
y Create, run, and save queries
y Update data using a query datasheety Create a query based on multiple tables
y Sort data in a query
y Filter data in a query
8/7/2019 3. Maintaining and Querying a Database
3/29
XP
Objectives
3
y Specify an exact match condition in a queryy Change the font size and alternating row color in a
datasheety Use a comparison operator in a query to match a range
of valuesy Use the And and Or logical operators in queries
y Create and format a calculated field in a query
y Perform calculations in a query using aggregate functions
and record group calculationsy Change the display of database objects in the Navigation
Pane
8/7/2019 3. Maintaining and Querying a Database
4/29
XP
Updating a Database
4
y Updating, or maintaining, a database is the process of
adding, modifying, and deleting records in database tables to
keep them current and accurate
8/7/2019 3. Maintaining and Querying a Database
5/29
XP
Finding Data in a Table
5
y The Find command allows you to search a table or query
datasheet, or a form, to locate a specific field value or part of
a field value
8/7/2019 3. Maintaining and Querying a Database
6/29
XP
Deleting a Record
6
y With the table in Datasheet view, click the row selector for
the record you want to delete
y In the Records group on the Home tab, click the Delete
button (or right-click the row selector for the record, andthen click Delete Record on the shortcut menu)
y In the dialog box asking you to confirm the deletion, click
the Yes button
8/7/2019 3. Maintaining and Querying a Database
7/29
XP
Deleting a Record
7
8/7/2019 3. Maintaining and Querying a Database
8/29
XP
Introduction to Queries
8
y Access provides powerful query capabilities that allowyou to do the following:y Display selected fields and records from a table
y Sort records
y Perform calculations
y Generate data for forms, reports, and other queries
y Update data in the tables in a database
y Find and display data from two or more tables
y A QueryWizard prompts you for information byasking a series of questions and then creates theappropriate query based on your answers
8/7/2019 3. Maintaining and Querying a Database
9/29
XP
Query Wizard
9
y When you use query byexample(QBE), you give Access
an example of the information you are requesting
y Click the Createtab on the Ribbon
yIn the Other group on the Create tab, click the QueryDesignbutton
8/7/2019 3. Maintaining and Querying a Database
10/29
XP
Query Wizard
10
8/7/2019 3. Maintaining and Querying a Database
11/29
XP
Creating and Running a Query
11
8/7/2019 3. Maintaining and Querying a Database
12/29
XP
Updating Data Using a Query
12
y You can update the data in a table using a query datasheet
y After updating the query, close the table
8/7/2019 3. Maintaining and Querying a Database
13/29
XP
Creating a Multitable Query
13
y A multitable query is a query based on more than one table
y If you want to create a query that retrieves data from
multiple tables, the tables must have a common field
8/7/2019 3. Maintaining and Querying a Database
14/29
XP
Sorting Data in a Query
14
y Sorting is the process of rearranging records in a specified
order or sequence
y To sort records, you must select the sort field, which is the
field used to determine the order of records in the datasheet
8/7/2019 3. Maintaining and Querying a Database
15/29
XP
Using AutoFilter to Sort Data
15
y The AutoFilterfeature enables you to quickly sort and
display field values in various ways
y Clicking the arrow in a column heading displays the
AutoFilter menu
8/7/2019 3. Maintaining and Querying a Database
16/29
XP
Sorting a Query Datasheet
16
y In the query datasheet, click the arrow on the column heading forthe field you want to sort
y In the menu that opens, click Sort A to Z for an ascending sort, orclick Sort Z to A for a descending sort
or
y In the query datasheet, select the column or adjacent columns onwhich you want to sort
y In the Sort & Filter group on the Home tab, click the Ascendingbutton or the Descending button
or
y In Design view, position the fields serving as sort fields from leftto right
y Click the right side of the Sort text box for the field you want tosort, and then click Ascending or Descending for the sort order
8/7/2019 3. Maintaining and Querying a Database
17/29
XP
Sorting a Query Datasheet
17
8/7/2019 3. Maintaining and Querying a Database
18/29
XP
UsingFilter By Selection
18
y A filteris a set of restrictions you place on the records in anopen datasheet or form to temporarilyisolate a subset of therecords
y In the datasheet or form, select part of the field value that
will be the basis for the filter; or, if the filter will be based onthe entire field value, click anywhere within the field value
y In the Sort & Filter group on the Home tab, click theSelection button, and then click the type of filter you want to
apply
8/7/2019 3. Maintaining and Querying a Database
19/29
XP
UsingFilter By Selection
19
8/7/2019 3. Maintaining and Querying a Database
20/29
XPDefining Record Selection Criteria
for Queries
20
y To tell Access which records you want to select, you must
specify a condition as part of the query
y A comparison operatorasks Access to compare the value
in a database field to the condition value and to select all therecords for which the relationship is true
8/7/2019 3. Maintaining and Querying a Database
21/29
XPDefining Record Selection Criteria
for Queries
21
8/7/2019 3. Maintaining and Querying a Database
22/29
XP
Specifying an Exact Match
22
y With an exact match, the value in the specified field must
match the condition exactly in order for the record to be
included in the query results
8/7/2019 3. Maintaining and Querying a Database
23/29
XPChanging a Datasheets
Appearance
23
y You can change the characteristics of a datasheet, including
the font type and size of text in the datasheet, to improve its
appearance or readability
y
By default, the rows in a datasheet are displayed withalternating background colors of white and light gray
8/7/2019 3. Maintaining and Querying a Database
24/29
XPChanging a Datasheets
Appearance
24
8/7/2019 3. Maintaining and Querying a Database
25/29
XPUsing a Comparison Operator
to Match a Range of Values
25
8/7/2019 3. Maintaining and Querying a Database
26/29
XPDefining Multiple Selection Criteria
for Queries
26
y Multiple conditions require you to use logical operators
to combine two or more conditions
y Use the And logical operator when you want a record
selected only if two or more conditions are met
y Use the Or logical operatorwhen you place conditions in
different Criteria rows
8/7/2019 3. Maintaining and Querying a Database
27/29
XPDefining Multiple Selection Criteria
for Queries
27
8/7/2019 3. Maintaining and Querying a Database
28/29
XP
Using Aggregate Functions
28
y Aggregate functionsperform arithmetic operations on
selected records in a database
y If you want to quickly perform a calculation using an
aggregate function in a table or query datasheet, you can use
theTotals button on the Home tab
8/7/2019 3. Maintaining and Querying a Database
29/29
XP
Using Aggregate Functions
29