A. Introduction |
B. Creating |
C. Opening |
D. Searching |
E. Filtering |
F. Sorting |
G. Primary Keys |
H. Importing |
I. Exporting |
J. Normalization |
K. Relationships |
L. Queries |
M. Reports |
StudentData | ||||
---|---|---|---|---|
StudentID | Name | Year | Major | FullTime |
032901 | Julie | 3 | Sociology | True |
090878 | David | 4 | Art | True |
073770 | Carolyn | 1 | Accounting | True |
010977 | Bill | 3 | Biology | False |
065618 | Arthur | 2 | Mathematics | True |
044541 | Nancy | 4 | Sociology | False |
By following a few basic rules, tables can be designed so that data
manipulation, storage, and retrieval are more accurate and efficient.
These rules are applied to a first draft of tables in a database. The rules
are as follows:
|
Filter by Selection may be repeated to produce compound filters.
Filter by Excluding Selection may be repeated or combined with other types of filtering.
Here are some filter criteria examples: >1, <2, ="M", <>"M", >=#1/1/2002# (Dates are delimited by #.)
When multiple filter criteria are supplied, the filtered records must match all of the criteria. This is equivalent to a logical and operation.
StudentData | ||||
---|---|---|---|---|
Name | Year | Major | FullTime | |
Carolyn | 1 | Accounting | True | carolynw@supermail.com |
Arthur | 2 | Mathematics | True | arthurj@supermail.com |
Bill | 3 | Biology | False | billk@supermail.com |
Julie | 3 | Sociology | True | julieh@supermail.com |
David | 4 | Art | True | davidr@supermail.com |
Julie | 4 | Sociology | False | nancya@supermail.com |
StudentData | |||||
---|---|---|---|---|---|
StudentID | Name | Year | Major | FullTime | Course |
032901 | Julie | 3 | Sociology | True | ENG202 SOC210 ISP121 |
090878 | David | 4 | Art | True | MAT111 |
073770 | Carolyn | 1 | Accounting | True | BUS215 ISP121 IT130 REL300 |
010977 | Bill | 3 | Biology | False | BIO200 CSC211 ENG202 |
065618 | Arthur | 2 | Mathematics | True | MAT215 CSC212 |
044541 | Nancy | 4 | Sociology | False | SOC301 |
This is our previous (see Introducton) StudentData table (Table A) with a Course field added. The data should be split into two tables, as shown below (Tables D and E). The repeating group, Course, has been moved into its own table, CourseData, to eliminate the repeating data group. The StudentData table is as it was originally (Table A). |
StudentData | ||||
---|---|---|---|---|
StudentID | Name | Year | Major | FullTime |
032901 | Julie | 3 | Sociology | True |
090878 | David | 4 | Art | True |
073770 | Carolyn | 1 | Accounting | True |
010977 | Bill | 3 | Biology | False |
065618 | Arthur | 2 | Mathematics | True |
044541 | Nancy | 4 | Sociology | False |
CourseData | |
---|---|
StudentID | Course |
032901 | ENG202 |
032901 | SOC210 |
032901 | ISP121 |
090878 | MAT111 |
073770 | BUS215 |
073770 | ISP121 |
073770 | IT130 |
073770 | REL300 |
010977 | BIO200 |
010977 | CSC211 |
010977 | ENF202 |
065618 | MAT215 |
065618 | CSC212 |
044541 | SOC301 |
|
|
Join of Doctors and Patients | ||||
---|---|---|---|---|
Doctors.DoctorID | DoctorName | PatientID | Name | Patients.DoctorID |
4444 | Jones | 11111 | Sally | 4444 |
4444 | Jones | 33333 | Winston | 4444 |
6666 | Smith | 55555 | Chloe | 6666 |
4444 | Jones | 77777 | Jason | 4444 |
6666 | Smith | 99999 | Mary | 6666 |
Drop Down Menu Caption | Information to Select |
---|---|
Left Table Name | Name of Table Containing Foreign Key |
Left Column Name | Name of Foreign Key |
Right Table Name | Name of Table Containing Associated Primary Key |
Right Column Name | Name of Primary Key |
The symbol 1 marks the primary key; the symbol ∞ marks the associated foreign key.
Creating and Running Query
Example
Using the database, Cruises.mdb, answer the queries:
Queries with Summaries or Groupings
Total queries can be run on any data that is organized into categories or groups. Usually fields having only a few different values are selected as grouping fields. For example, in the Cruises.mdb database, the table Cruises could be grouped by Company name, Ship, or Destination. For instance, if we wanted to know the average first class price for each company we would choose as our Group by field Company name and the other field would be FC price.
How to Display the Total Row
Using the Group By Option
The Group By option allows the user to specify a field as a grouping field. The data will be organized and displayed into groups based on the values in that field. For example, you can group together all records that come from a specific cruise company, so that all "Gateway Cruises" are grouped together and all "Velo Cruise Line" cruises are grouped together, etc. Subtotals can be calculated in each group for any numeric fields. For example, we could calculate the average price of a first class cabin. So we would have the average price subtotal for "Gateway Cruises," for "Velo Cruise Line," and so forth.
The Group By option should be specified for only one field, unless subgroupings are needed. For example, you could group by Company name and within that grouping it's possible to group all ships. Be careful that only those columns that are part of the grouping scheme contain the value Group By in the Group row. Group By is the default value.
How to Calculate Subtotals
Male | Female | |
---|---|---|
Business | 21.3 | 20.7 |
Math | 19.8 | 21.0 |
Communications | 20.9 | 20.8 |
Psychology | 20.2 | 19.5 |
Row headings = major Column headings = gender Values = average age
|
There are three examples of Crosstab queries in the Cruises1.mdb database. The one called qryAverage, computes the average first class price for each cruise company grouped by departure location. The qryAverage2 is the same as qryAverage except that it just gives the results for Departure Locations Miami and Los Angeles. The qryCount query counts the number of entries in each of the company-departure location groups. When doing a count, it doesn't matter what field you use in the Values column.
Creating a Crosstab Query in Design View
Creating a Crosstab query in Design view gives you more flexibility than the wizard. The most important thing to remember is to specify one or more Row Headings, only one Column Heading, and only one Value field. Here is what to do:
To do this, enter the expression [Text of Prompt] in the Criteria row for the field for which you are selecting a value interactively. For example, suppose, in the Cruises database, we wanted to be able to enter a destination and get all cruise infromation associated with that destination. Someone else may want information for a different destination. The query qryDestination has [Enter a destination:] entered under Criteria in the Destination column.