The Visibooks Guide to Base 2.0
by Jill & Kevin Jordan
www.visibooks.com
The Visibooks Guide to Base 2.0 Copyright ...
24 downloads
507 Views
11MB Size
Report
This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Report copyright / DMCA form
The Visibooks Guide to Base 2.0
by Jill & Kevin Jordan
www.visibooks.com
The Visibooks Guide to Base 2.0 Copyright Copyright © 2006 by Visibooks™, LLC. All rights reserved.
Trademarks and Disclaimer Visibooks™ is a trademark of Visibooks, LLC. All brand and product names in this book are trademarks or registered trademarks of their respective companies. Visibooks™ makes every effort to ensure that the information in this book is accurate. However, Visibooks™ makes no warranty, expressed or implied, with respect to the accuracy, quality, reliability, or freedom from error of this document or the products described in it. Visibooks™ makes no representation or warranty with respect to this book’s contents, and specifically disclaims any implied warranties or fitness for any particular purpose. Visibooks™ disclaims all liability for any direct, indirect, consequential, incidental, exemplary, or special damages resulting from the use of the information in this document or from the use of any products described in it. Mention of any product does not constitute an endorsement of that product by Visibooks™. Data used in examples are intended to be fictional. Any resemblance to real companies, people, or organizations is entirely coincidental.
ISBN 1597060380
Table of Contents Database Basics ............................................. 1 Create a new database ..........................................................................2 Create tables ........................................................................................12 Create records......................................................................................21 Create forms .........................................................................................29 Create queries ......................................................................................42 Create reports ......................................................................................49
Working with Tables ..................................... 65 Modify tables ........................................................................................66 Create new tables.................................................................................76 Specify data types................................................................................79 Specify field properties .......................................................................85 Edit records ..........................................................................................88 Find records .........................................................................................91 Sort and filter records..........................................................................96 Create table relationships .................................................................101
TABLE OF CONTENTS
i
Working with Forms ....................................113 Modify forms ...................................................................................... 114 Add/delete records ............................................................................ 119 Edit records........................................................................................ 121 Find records....................................................................................... 123 Filter records...................................................................................... 126
Working with Queries ..................................131 Create queries.................................................................................... 132 Sort results......................................................................................... 141 Add criteria......................................................................................... 143 Employ Boolean operators ............................................................... 146
ii
TABLE OF CONTENTS
Database Basics In this section, you’ll learn how to: • Create a new database • Create tables • Create records • Create forms • Create queries • Create reports
DATABASE BASICS
1
Create a new database 1.
Start OpenOffice.org Base. Your screen should look like this:
2
DATABASE BASICS
2.
In the Database Wizard window, click Create a new database.
Then click the
button.
DATABASE BASICS
3
3.
When the Save as window appears, create a new folder in the My Documents folder called Practice Base Files.
Tip: To create a new folder, make sure the My Documents
folder appears as the Save In folder. Then click the
4.
icon.
Double-click the Practice Base Files folder. It should appear as the Save In folder.
4
DATABASE BASICS
5.
In the File name box, type: Family.odb
Tip: Base will automatically add a file extension for you when you leave the Automatic file name extension box checked.
DATABASE BASICS
5
6.
Click the
button.
The window for the Family database should open:
6
DATABASE BASICS
Identify database elements Elements of databases A database stores information in an organized way, and makes it easy to get information in and out. Tables store data within the database. Forms make it easy to put data into tables. Queries pull out specific data. Reports put data in an easily-read format.
Form
Query
Table
Table
Report
DATABASE BASICS
7
1.
8
In the Database list, click Tables.
DATABASE BASICS
2.
Click Queries.
DATABASE BASICS
9
3.
10
Click Forms.
DATABASE BASICS
4.
Click Reports.
5.
Click Tables.
DATABASE BASICS
11
Create tables 1.
12
Click Create Table in Design View.
DATABASE BASICS
A blank table should open with the columns Field Name, Field Type, and Description:
DATABASE BASICS
13
Name fields in Design View 1.
Click in the box under the Field Name column header:
2.
Type: First Name
14
DATABASE BASICS
3.
Press the ENTER key on your keyboard. The Design View of the table should look like this:
The field type for First Name can stay Text [VARCHAR].
DATABASE BASICS
15
4.
Click in the box under where you just typed First Name.
Type: Last Name It should look like this:
5. 16
Press the ENTER key on your keyboard.
DATABASE BASICS
6.
In the same way, create the following fields: City Zip Phone Number The table should now look like this:
DATABASE BASICS
17
7.
On the Menu Bar, click File, then Save.
8.
When the Save As window appears, type: My Family in the Table Name box.
9.
18
Click the
DATABASE BASICS
button.
10.
When the alert window that reads No primary key appears, click the
button.
Base will insert an ID field—the Key field—in the table:
DATABASE BASICS
19
11.
On the Menu Bar, click File, then Close.
The key field When the alert window popped up, and you clicked the Base added the ID field to the table.
button,
The ID field is now the table’s primary key, or key field. That means it can’t contain any duplicates. Every table should have a key field. For example, if a hospital keeps a database, each patient can have a unique ID number in the key field. That way, if it has more than one patient named John Baker, it can easily distinguish John Baker, ID #326 in for a checkup, from John Baker, ID #298 who needs his gall bladder removed.
20
DATABASE BASICS
Create records 1.
Double-click the table My Family in the Tables list.
2.
Click in the box under the ID column header.
3.
Type: 1
DATABASE BASICS
21
4.
Click in the box under the First Name column header.
5.
Type: Elvis
6.
Press the TAB key on your keyboard. The table should now look like this:
7.
Type: Presley then press the TAB key.
8.
Type: Baltimore then press TAB.
22
DATABASE BASICS
9.
Type: 21212 then press TAB.
10.
Type: 4105551212 then press TAB. The table should now look like this:
Tip: Notice how the cursor in the row selector has moved down
to the second (new) record. When you move on to a new record, Base automatically saves the previous record.
DATABASE BASICS
23
Add new fields
24
1.
On the Menu Bar, click File, then Close.
2.
Right-click the My Family table.
DATABASE BASICS
3.
When the menu appears, click Edit.
The table should appear in Design View:
DATABASE BASICS
25
4.
Click the box under Phone Number and type: State
26
5.
Press the ENTER key.
6.
On the Menu Bar, click File, then Save.
7.
On the Menu Bar, click File, then Close.
DATABASE BASICS
8.
Double-click the My Family table.
9.
Click inside the new State field for the first record.
10.
Type: MD
DATABASE BASICS
27
11.
Press TAB until the cursor moves down to a new record.
Record number 1 is saved and complete.
12.
28
On the Menu Bar, click File, then Close.
DATABASE BASICS
Create forms 1.
In the Database list, click Forms.
DATABASE BASICS
29
2.
30
Click Use Wizard to Create Form.
DATABASE BASICS
3.
When the Form Wizard window appears, click the
button.
All the table fields should be added to the form:
4.
Click the
button.
DATABASE BASICS
31
5.
When the next screen appears, leave Add Subform unselected and click the
32
DATABASE BASICS
button.
6.
When the next screen appears, make sure Columnar – Labels on Top is selected.
DATABASE BASICS
33
Then click the
34
DATABASE BASICS
button three times.
7.
When the Set the name of the form screen appears, type: My Family Data Input Form in the box.
DATABASE BASICS
35
8.
Click the
button.
The form should open and look like this:
36
DATABASE BASICS
Add a new record 1.
In the form window, click the
button.
A blank record should appear:
DATABASE BASICS
37
2.
Click in the ID box, then type: 2
3.
38
Press TAB to advance to the First Name box.
DATABASE BASICS
4.
Type: Bo then press the TAB key.
5.
Type: Diddley then press the TAB key.
6.
Type: Richmond then press the TAB key.
7.
Type: 23220 then press the TAB key.
8.
Type: 8005557890 then press the TAB key.
DATABASE BASICS
39
9.
Type: VA The form should now look like this:
40
DATABASE BASICS
10.
Press the TAB key again. The form should progress to a new, blank record:
The old record has been saved.
11.
On the Menu Bar, click File, then Close to return to the database window.
DATABASE BASICS
41
Create queries What’s a query? A query is a way to get specific information from the database. Essentially, it’s a question. You use queries to ask the database things like, “Who are my customers in Montana?”, or “How many pipe fittings have I sold this month?”
1.
42
In the Database list, click Queries.
DATABASE BASICS
2.
Click Use Wizard to Create Query.
DATABASE BASICS
43
3.
When the Query Wizard opens, double-click My Family.First Name in the Available Fields list.
My Family.First Name should appear in the Fields in the Query column:
44
DATABASE BASICS
4.
Click the
button.
This should add the Last Name field to the Fields in the Query list:
5.
Double-click My Family.Phone Number.
DATABASE BASICS
45
This should add the Phone Number field to the Fields in the Query list:
6.
46
Click the
DATABASE BASICS
button four times.
7.
When the Overview screen appears, in the Name of the query box type: Names and Numbers
8.
Click the
button.
The query is automatically saved and executed. It should look like this:
DATABASE BASICS
47
9.
48
On the Menu Bar, click File, then Close to return to the database window.
DATABASE BASICS
Create reports 1.
In the Database list, click Reports.
DATABASE BASICS
49
2.
Click Use Wizard to Create Report.
3.
When the Report Wizard window appears, click the Tables or Queries drop-down arrow. When the list appears, click Table: My Family.
50
DATABASE BASICS
4.
Click the report list.
button to move all the fields into the Fields in
DATABASE BASICS
51
5.
In the Fields in report list box, click ID, then click the The ID field should be removed. The report wizard should now look like this:
6.
52
Click the
DATABASE BASICS
button.
button.
7.
When the Labeling fields screen appears, click the button.
DATABASE BASICS
53
8.
54
When the Grouping screen appears, click the
DATABASE BASICS
button.
9.
When the Sort options screen appears, click the Sort by dropdown arrow.
Then click State in the list.
10.
Click the
button.
DATABASE BASICS
55
Choose layout and style 1.
When the Choose layout screen appears, make sure Default is selected in the Layout of data section.
Then click the
button.
Tip: The Layout of data section allows you to customize the
look and feel of your reports. You can click through the different layouts and see them applied to your report in the background.
56
DATABASE BASICS
View the report 1.
When the Create report screen appears, make sure the Title of report box reads: My Family
Make sure the Create report now radio button is selected.
DATABASE BASICS
57
2.
Click the
button.
The report is automatically created, saved and opened. It should look like this:
58
3.
On the Menu Bar, click File, then Close to return to the Family database window.
4.
On the Menu Bar, click File, then Save to save the Family database.
DATABASE BASICS
5.
On the Menu Bar, click File, then Exit to close Base.
DATABASE BASICS
59
Practice: Database Basics 1.
Open OpenOffice.org Base.
2.
Create a blank database in the Practice Base Files folder called Library.odb.
3.
Create a new table with these fields: ID Title Author Genre Date Purchased Number of Pages
4.
Save the table as Books. Allow Base to create a Primary Key.
5.
60
Rename the ID field (the Primary Key) Book ID.
DATABASE BASICS
6.
Enter these data into the table to create the first record: Title: Ideas & Opinions Author: Albert Einstein Genre: Nonfiction Date purchased: 11/18/2005 Number of Pages: 384 It should look like this:
7.
Close the Books table.
8.
Create a form for the Books table.
DATABASE BASICS
61
9.
Save it as Books Table Data Input. It should look like this:
Use the form to enter information for four more books. Tip: Feel free to make things up.
10.
Create a query that pulls out this information: Title Genre Number of Pages
62
DATABASE BASICS
11.
Save the query as Quick Book Notes.
12.
Run the query. It should look like this:
13.
Create a report based on the Books table.
14.
Include all the fields of the Books table in the report, and sort the records based on Genre. Tip: Format the report using the Default style.
DATABASE BASICS
63
15.
Name the report Book Inventory. It should look like this:
64
16.
Close the report.
17.
Exit OpenOffice.org Base.
DATABASE BASICS
Working with Tables In this section, you’ll learn how to: • Modify tables • Create new tables • Specify data types • Specify field properties • Edit records • Find records • Sort and filter records • Create table relationships
WORKING WITH TABLES
65
Modify tables 1.
Open a web browser and go to: www.visibooks.com/books/base2
2.
Right-click the FlowerStore.odb link. When the menu appears, click Save Link Target As.
66
WORKING WITH TABLES
3.
When the Save As window appears, open the Practice Base Files folder on your hard drive. Then click the
4.
button.
Wait for the database to download completely, then close the web browser.
WORKING WITH TABLES
67
Open an existing database
68
1.
Start Base.
2.
When the Database Wizard opens, click the Open an existing database file radio button.
WORKING WITH TABLES
3.
Click the
button.
WORKING WITH TABLES
69
4.
70
Open the Practice Base Files folder, then double-click FlowerStore.odb.
WORKING WITH TABLES
The FlowerStore database window should now look like this:
WORKING WITH TABLES
71
Adjust table layout 1.
72
Double-click the Customers table to open it.
WORKING WITH TABLES
2.
Place your cursor on the divider between the Phone Number and Fax Number column headings.
The cursor should turn into a double-headed arrow:
WORKING WITH TABLES
73
3.
Double-click. The Phone Number column should resize to fit the widest piece of data in that field:
Tip: Instead of double-clicking, you can also drag column
heading dividers to set column widths manually.
74
WORKING WITH TABLES
4.
Double-click the divider between the City and State column headings. The City field should resize to fit the data in it.
5.
Click the window’s
button to close the Customers table.
WORKING WITH TABLES
75
Create new tables 1.
Click Create Table in Design view.
A blank table will open in Design View:
76
WORKING WITH TABLES
2.
In the first box in the Field Name column, type: Order ID then press the TAB key. It should look like this:
3.
On the Toolbar, click the
icon.
WORKING WITH TABLES
77
4.
When the Save As window appears, type: Orders in the Table Name box.
5.
Click the
6.
When the alert window appears, click the
button.
Tip: You’ll assign a Primary Key later.
78
WORKING WITH TABLES
button.
Specify data types Assign the AutoNumber data type 1.
In the Data Type column beside the Order ID field, click the drop-down arrow. When the list appears, click Integer.
2.
Under Field Properties, beside the AutoValue field, click the drop-down arrow. When the list appears, click Yes.
WORKING WITH TABLES
79
3.
In the Description column, type: This is the Generic Order ID Number then press TAB.
Tip: Filling in a Description is optional, but it helps you to
remember what sort of information is supposed to be stored in a field.
80
WORKING WITH TABLES
Assign the Date/Time data type 1.
In the Field Name column, in the second row, type: Order Date then press TAB.
2.
In the Data Type column, click the drop-down arrow.
3.
When the menu appears, click Date/Time, then press TAB.
WORKING WITH TABLES
81
4.
In the Description column, type: Date the order was placed then press TAB.
82
WORKING WITH TABLES
Assign a Primary Key 1.
Right-click the Order ID field.
2.
When the menu appears, click Primary Key.
The field should now show a key beside it:
WORKING WITH TABLES
83
3.
84
On the Menu Bar, click File, then Save.
WORKING WITH TABLES
Specify field properties 1.
Click in the Order Date field.
2.
In the Field Properties section of the window, click the button next to the Format example box.
WORKING WITH TABLES
85
3.
In the menu of formats that appears, click 12/31/99.
Then click the
button.
The Order Date’s Format example field should now look like this:
86
WORKING WITH TABLES
4.
On the Toolbar, click the
icon.
Tip: If a Warning window appears, click the
button.
The table design window should now look like this:
5.
On the Menu Bar, click File, then Close to return to the FlowerStore database window.
WORKING WITH TABLES
87
Edit records
88
1.
Open the Customers table.
2.
Click inside the Customer Name field for record number 1, between the w and s in Andrews Floral.
3.
Insert an apostrophe.
4.
Press TAB eight times to move to the Phone Number field.
WORKING WITH TABLES
5.
Type: 2125554569 It should replace the previous text:
6.
Click in any other record. Tip: Remember—changed data in a record is saved when you
move off that record. The Customers table should now look like this:
WORKING WITH TABLES
89
Delete records 1.
Right-click the button for HomeVase’s record.
2.
In the menu that appears, click Delete Rows.
3.
When the alert window appears, click the
button.
Tip: Once a record has been deleted from the database, it
cannot be recovered.
90
WORKING WITH TABLES
Find records Navigate records 1.
In the Customers table window, click the button.
(Last Record)
The cursor should be in the last record in the database:
2.
Click the
(Previous Record) button.
The cursor should be in the previous record.
WORKING WITH TABLES
91
3.
Click the
(First Record) button.
The cursor should be in the first record.
4.
Click the
(Next Record) button.
The cursor should be in the second record.
5.
Click the
(New Record) button.
The Customers table should look like this:
92
WORKING WITH TABLES
Search for records 1.
Click the Company Name column header.
The table should look like this:
2.
On the Toolbar, click the
(Find) icon.
WORKING WITH TABLES
93
3.
When the Record Search window appears, type: Love in the Search for Text box.
4.
94
In the Position list, click the drop-down arrow, then anywhere in the field.
WORKING WITH TABLES
5.
Click the
button.
The Customers table should now look like this, with Love Me True highlighted:
6.
In the Find and Replace window, click the
button.
WORKING WITH TABLES
95
Sort and filter records Sort in descending order 1.
Click the Company Name column header.
The table should look like this:
2.
96
On the Toolbar, click the
WORKING WITH TABLES
(Sort Descending) icon.
The Customers table should now look like this, with the Company Names arranged in descending alphabetical order:
WORKING WITH TABLES
97
Sort in ascending order 1.
Click the Customer ID column header to highlight the column.
2.
On the Toolbar, click the
(Sort Ascending) icon.
The Customers table should now look like this, with the customer ID numbers arranged in ascending order:
98
WORKING WITH TABLES
Filter records 1.
Click in the State field for Pete’s Moss.
Notice that the State is Virginia.
2.
On the Toolbar, click the
(AutoFilter) icon.
The Customers table should now look like this, showing all customers whose State is Virginia:
WORKING WITH TABLES
99
3.
On the Toolbar, click the
(Remove Filter) icon.
The Customers table should show its original contents:
4.
On the Menu Bar, click File, then Close to return to the FlowerStore database window.
When to filter Filtering records works like a query, bringing up specific information from a table. But unlike a query, your filtering doesn’t remain part of the database. When you perform a query and save it, the query remains with the database, even after you close it. Filtering does not. Since you can’t save filtering like a query, filter records when you need quick results. Think of filtering as a temporary, quick, “on the spot” query.
100
WORKING WITH TABLES
Create table relationships What are “relationships?” Relationships are links that associate a field in one table with a field in another. An example is a school database with two tables: • Students • Classes The Students table holds students’ names and addresses: Students Student Name John Jane
Address Elm St. Oak St.
The Math Class table holds information about the students in math class: Math Class Student Name John Jane
Grade A B
Both tables have a Student Name field. By linking the Student Name fields, you make sure that John in the Students table is the same John listed in the Math Class table: Students Student Name John Jane
Address
Math Class Student Name John Jane
Grade
WORKING WITH TABLES
101
Examine current table relationships 1.
On the Menu Bar, click Tools, then Relationships.
2.
When the Add Tables window appears, double-click Customers.
102
WORKING WITH TABLES
The Customers table should appear in the Relationships work area:
3.
In the Add Tables window, double-click Employees. The Employees table should appear in the Relationships work area:
WORKING WITH TABLES
103
4.
Double-click Order Details.
5.
Double-click Orders.
6.
Double-click Products.
7.
In the Add Tables window, click the
104
WORKING WITH TABLES
button.
The relationships window should now look like this:
WORKING WITH TABLES
105
Add relationships 1.
Place the cursor on the Title Bar at the top of the Employees table.
2.
Click and drag the Employees table to place it under the Customers table.
106
WORKING WITH TABLES
3.
Click and drag the Orders table to place it between the Customers table and Order Details table.
4.
Click the Order ID field in the Order Details table, then drag it and rest it on top of the Order ID field in the Orders table.
The Orders table should look like this:
WORKING WITH TABLES
107
5.
Release the mouse button. The relationships window should now look like this:
The Order ID field in the Orders table is linked to the Order ID field in the Order Details table. The same Order ID number in both tables refers to the same order.
6.
On the Menu Bar, click File, then Close to return to the FlowerStore database window.
7.
When the alert window appears, click the
8.
On the Menu Bar, click File, then Exit.
108
WORKING WITH TABLES
button.
Practice: Working with Tables 1.
Start Base.
2.
Open the Library database in the Practice Base Files folder.
3.
Create a new table in Design View.
4.
Add the following fields in the new table (data type in parentheses): Author ID (Autonumber) Author Name (Text) Good Author? (Yes/No)
WORKING WITH TABLES
109
5.
Set the Author ID field as the key field. The table design should look like this:
6.
Save the table as Authors, then close it.
7.
Open the Books table and view it in Design View.
8.
Change the name of the Author field to Author ID. Set its data type to Integer.
110
WORKING WITH TABLES
9.
Change the data type of the Date Purchased field to Date/Time, and its format to 12/31/99.
10.
Save the Books table, then close it. Tip: An alert window will appear saying there was an error,
due to changing the Date Purchased data type. Z Click the
button.
11.
Open the Relationship design window.
12.
Add the two tables: Books and Authors.
13.
Link the Author ID fields of the Author and Books tables.
WORKING WITH TABLES
111
When you’re done, it should look like this:
14.
Close the Relationship design window and save the changes.
15.
Exit Base.
112
WORKING WITH TABLES
Working with Forms In this section, you’ll learn how to: • Modify forms • Add/delete records • Edit records • Find records • Filter records
WORKING WITH FORMS
113
Modify forms 1.
Start Base, then open the FlowerStore database.
2.
In the Database list, click Forms.
114
WORKING WITH FORMS
3.
Right-click Customer Form.
4.
When the menu opens, click Edit.
WORKING WITH FORMS
115
Tip: Clicking Edit opens the form in Writer. The form should look like this in Writer:
116
WORKING WITH FORMS
Change field position 1.
Click the Address 2 box to select it.
2.
Position the cursor over the Address 2 box. It should turn into a four-arrow “move” cursor:
WORKING WITH FORMS
117
3.
Click-and-drag the box to line it up with the other boxes.
Release the mouse button. The form should now look like this:
118
WORKING WITH FORMS
Add/delete records Add a new record 1.
Click the
icon to toggle the view.
2.
Click the
(New Record) button.
Fill in the following information: Amy Moore Gifts & Buds 1214 Maryland Ave. Suite 13 Washington, DC 20001 2025556113 2025556114
3.
Click the one.
button to save the record and advance to a new
WORKING WITH FORMS
119
Delete records 1.
Click the button to go back to record number 6, the one you just added.
2.
On the Toolbar, click the
3.
When the alert window appears, click the
120
WORKING WITH FORMS
(Delete Record) icon.
button.
Edit records Navigate to a specific record number 1.
Click in the Record box.
2.
Highlight the current record number, then type: 2
3.
Press the ENTER key. The form should now show record number 2:
WORKING WITH FORMS
121
Edit data in a record 1.
Delete the contents of the Street Address field.
2.
Type: 476 New York Ave.
3.
Press the TAB key. The record should look like this:
122
WORKING WITH FORMS
Find records 1.
Click the
2.
Click in the Company Name box to place the cursor there.
3.
On the Toolbar, click the
button.
icon.
WORKING WITH FORMS
123
4.
When the Record Search window appears, type: Floral in the Search for Text box.
124
WORKING WITH FORMS
5.
Click the
button.
The window should look like this:
6.
Click the
button.
WORKING WITH FORMS
125
Filter records 1.
Click in the State box.
2.
On the Toolbar, click the
126
WORKING WITH FORMS
(Autofilter) icon.
The form should now look like this:
Tip: Notice the number of records now reads 1 of 2.
3.
On the Toolbar, click the
4.
On the menu bar, click File, then Close.
icon.
When the Alert window appears, click the
button.
WORKING WITH FORMS
127
The database window should now look like this:
5.
128
On the Menu Bar, click File, then Exit to close Base.
WORKING WITH FORMS
Practice: Working with Forms 1.
Open a web browser and go to: www.visibooks.com/books/base2
2.
Right-click the Library2.odb link, and save the database in the Practice Base Files folder.
3.
Close the browser and start Base.
4.
Open the Library 2 database.
5.
Using the Form Wizard, create a new form based on the Authors table, using all the fields.
6.
Save the form as Author Information Input.
7.
Using the form, enter information for John Grisham: Author ID: (Autonumber) Author Name: John Grisham Good Author? Yes
8.
Close the form.
9.
Open the Author table to check that John Grisham’s information was entered.
10.
Close the Author table.
WORKING WITH FORMS
129
11.
130
Exit Base.
WORKING WITH FORMS
Working with Queries In this section, you’ll learn how to: • Create queries • Sort results • Add criteria • Employ Boolean operators
WORKING WITH QUERIES
131
Create queries 1.
Start Base, and open the FlowerStore database.
2.
In the Database list, click Queries.
3.
Click Create Query in Design View.
132
WORKING WITH QUERIES
The Query Design window should appear:
WORKING WITH QUERIES
133
4.
In the Add Tables window, click Customers.
Then click the
5.
134
Click the
WORKING WITH QUERIES
button. button.
This adds the Customers table to the query. The query window should look like this:
WORKING WITH QUERIES
135
Add fields to query 1.
Click the arrow in the first column’s Field box.
2.
When the list appears, click Customers.Customer ID.
136
WORKING WITH QUERIES
The query design grid should look like this:
3.
Drag the First Name field from the Customers table to the second column of the query design grid.
Release the mouse button.
WORKING WITH QUERIES
137
The First Name field should appear in the design grid:
4.
Drag the Last Name field to the design grid. The design grid should look like this:
The query is now set up to show the Customer ID, First Name, and Last Name of each customer in the Customers table.
138
WORKING WITH QUERIES
Run the query 1.
On the Toolbar, click the
icon.
The query window should now look like this:
WORKING WITH QUERIES
139
The query shows the Customer ID, First Name, and Last Name of each customer in the Customers table:
140
WORKING WITH QUERIES
Sort results 1.
In the Last Name field, click in the Sort row. When the drop-down arrow appears, click it, then click Ascending.
It should look like this:
WORKING WITH QUERIES
141
2.
On the Toolbar, click the
icon.
The query should run, and sort the records alphabetically by Last Name:
3.
In the Last Name field, click in the Sort row, then click (not sorted).
It should look like this:
142
WORKING WITH QUERIES
Add criteria 1.
In the query’s Customer table, scroll down to the State field.
2.
Add the State field to the query design grid.
3.
In the State field, click in the Criterion row.
WORKING WITH QUERIES
143
4.
Type: VA
5.
Press the ENTER key. It should look like this:
Tip: Notice that Base automatically surrounded the VA criterion with quotes. That’s because the State field stores text data. In
database query language, quotes signify a string of text. If the field stored number data, Base wouldn’t have added anything.
144
WORKING WITH QUERIES
6.
On the Toolbar, click the
icon.
The query results should look like this:
It has returned all customers who live in the State of VA.
WORKING WITH QUERIES
145
Employ Boolean operators What are Boolean operators? Boolean operators are expressions such as AND, OR, NEITHER, and NOR that allow you to add multiple criteria to a query. They take their name from George Boole, the mathematician who first used them. If you had a T-shirt store with an Base database, for instance, and you wanted to find out how many of your California customers had ordered blue T-shirts, you’d employ the AND operator in your query:
customers from California AND
who also bought blue T-shirts If you wanted to see how many customers were from California (these California customers could have bought T-shirts of any color), and how many customers bought blue T-shirts (these blue T-shirt customers could be from anywhere), you’d employ the OR operator:
customers from California OR
customers who bought blue T-shirts
146
WORKING WITH QUERIES
Employ the OR operator 1.
In the State field, click in the Or row under the criterion VA.
2.
Type: MD then press the ENTER key. The design grid should look like this:
WORKING WITH QUERIES
147
Tip: The two common Boolean operators are AND and OR.
They’re easily confused. If you don’t know which to use, ask yourself the purpose of the query: Do I want to find customers with a state of both Virginia AND Maryland? No—a customer can’t be in two places at once. Do I want to find customers with a state of either Florida OR Maryland? That makes sense, so this query would use the OR operator.
3.
Click the
icon.
The query results should look like this:
148
WORKING WITH QUERIES
Employ the AND operator 1.
Remove the query criteria from the State field. Tip: Highlight them, then press the DELETE key. The design grid should be blank:
2.
Add the Company Name field to the query: Drag it from the field list in the Customers table and drop it in the blank field to the right of the State field.
WORKING WITH QUERIES
149
3.
In the Company Name field, click in the Criterion row.
4.
Type: LIKE A* then press the ENTER key. Tip: An asterisk (*) stands for any character or combination of characters. For instance, Ap* would match Ape, Aptitude, Apparent, etc.
The LIKE keyword is used to search for a pattern.
5.
Click the
icon.
The query results should look like this:
The query shows all companies whose names begin with A.
6.
150
On the Menu Bar, click File, then Save.
WORKING WITH QUERIES
7.
When the Save As window appears, type: Companies that begin with A in the Query Name box.
8.
Click the
9.
On the Menu Bar, click File, then Close.
button.
You should return to the FlowerStore database window.
10.
Exit the database and close Base.
WORKING WITH QUERIES
151
Practice: Working with Queries 1.
Start Base.
2.
Open the Library 2 database.
3.
Create a new query in Design view based on the Authors table.
4.
Add all the fields to the design grid.
5.
Sort Authors Names in Ascending order.
6.
Add the criteria Yes to the Good Author field.
7.
Run the query. Its results should look like this:
8. 152
Close the query, saving it as Good Authors.
WORKING WITH QUERIES
9.
Exit Base.
WORKING WITH QUERIES
153
154
WORKING WITH QUERIES
Glossary Boolean Operators Boolean logic is a system of logical thought developed by George Boole. Boolean operators allow you to construct complex queries which can be understood by computers. The most common Boolean operators are “AND” and “OR”. Data A series of facts. When data is organized, it becomes useful information, which can be processed and used to draw conclusions. Database A collection of information organized into tables of data. Field A single unit of data stored as part of a database record. Form A database object primarily used to enter or display data. Key Field A field in a table that can contain no duplicates. The key field is each record’s unique identifier. Query A set of questions presented to a database to retrieve specific information. Record One row in a given table. In a relational database, records correspond to rows in each table. Relationship An association established between common fields in two tables.
GLOSSARY
155
Report Presents information retrieved from a table or query in a preformatted, easy-to-read way. Select Query A query that asks a question about the data stored in tables, and provides a result in the form of a datasheet. Table A collection of rows and columns that organize data. Update Query A query that changes a set of records according to specified criteria.
156
GLOSSARY
Where to Get Visibooks If you liked using this book, and would like to use more like it, visit: www.visibooks.com
Visibooks offers more than 30 titles on subjects such as: • Computer Basics • Microsoft Office • Desktop Linux • OpenOffice.org • Web Site Layout • Web Graphics • Web Programming
Visibooks: the simplest way to learn and teach computer subjects.
www.visibooks.com