On the Menu Bar, click File, then Close to return to the database window... On the Menu Bar, click File, then Close to return to the database window... When the Report Wizard window ap
Trang 2The Visibooks Guide
to Base 2.0
by Jill & Kevin Jordan
Trang 3The 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
Trang 4Table 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
Trang 5TABLE OF CONTENTS
ii
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
Trang 6Database Basics
In this section, you’ll learn how to:
• Create a new database
Trang 7DATABASE BASICS
2
Create a new database
1 Start OpenOffice.org Base
Your screen should look like this:
Trang 82 In the Database Wizard window, click Create a new database
Then click the button
Trang 9DATABASE BASICS
4
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
4 Double-click the Practice Base Files folder
It should appear as the Save In folder
Trang 105 In the File name box, type:
Family.odb
Tip: Base will automatically add a file extension for you when
Trang 11DATABASE BASICS
6
6 Click the button
The window for the Family database should open:
Trang 12Identify 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
Table
Query
Report Form
Table
Trang 13DATABASE BASICS
8
1 In the Database list, click Tables
Trang 142 Click Queries
Trang 15DATABASE BASICS
10
3 Click Forms
Trang 164 Click Reports
5 Click Tables
Trang 18A blank table should open with the columns Field Name, Field
Type, and Description:
Trang 19DATABASE BASICS
14
Name fields in Design View
1 Click in the box under the Field Name column header:
2 Type:
First Name
Trang 203 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]
Trang 21It should look like this:
5 Press the ENTER key on your keyboard
Trang 226 In the same way, create the following fields:
City Zip Phone Number
The table should now look like this:
Trang 23DATABASE BASICS
18
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 Click the button
Trang 2410 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:
Trang 25
DATABASE BASICS
20
11 On the Menu Bar, click File, then Close
The key field
When the alert window popped up, and you clicked the button,
Base added the ID field to the table
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
Trang 26Create 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
Trang 276 Press the TAB key on your keyboard
The table should now look like this:
Trang 28then 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
Trang 29DATABASE BASICS
24
Add new fields
1 On the Menu Bar, click File, then Close
2 Right-click the My Family table
Trang 303 When the menu appears, click Edit
The table should appear in Design View:
Trang 31DATABASE BASICS
26
4 Click the box under Phone Number and type:
State
5 Press the ENTER key
6 On the Menu Bar, click File, then Save
7 On the Menu Bar, click File, then Close
Trang 328 Double-click the My Family table
9 Click inside the new State field for the first record
10 Type:
MD
Trang 33DATABASE BASICS
28
11 Press TAB until the cursor moves down to a new record
Record number 1 is saved and complete
12 On the Menu Bar, click File, then Close
Trang 34Create forms
1 In the Database list, click Forms
Trang 35DATABASE BASICS
30
2 Click Use Wizard to Create Form
Trang 363 When the Form Wizard window appears, click the button
All the table fields should be added to the form:
4 Click the button
Trang 37DATABASE BASICS
32
5 When the next screen appears, leave Add Subform unselected
and click the button
Trang 386 When the next screen appears, make sure Columnar – Labels
on Top is selected
Trang 39DATABASE BASICS
34
Then click the button three times
Trang 407 When the Set the name of the form screen appears, type:
My Family Data Input Form
in the box
Trang 41DATABASE BASICS
36
8 Click the button
The form should open and look like this:
Trang 42Add a new record
1 In the form window, click the button
A blank record should appear:
Trang 4610 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
Trang 47A 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?”
Trang 482 Click Use Wizard to Create Query
Trang 49DATABASE BASICS
44
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:
Trang 504 Click the button
This should add the Last Name field to the Fields in the Query
list:
5 Double-click My Family.Phone Number
Trang 52
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:
Trang 53DATABASE BASICS
48
9 On the Menu Bar, click File, then Close to return to the database
window
Trang 54Create reports
1 In the Database list, click Reports
Trang 55DATABASE BASICS
50
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
Trang 564 Click the button to move all the fields into the Fields in
report list
Trang 57DATABASE BASICS
52
5 In the Fields in report list box, click ID, then click the button
The ID field should be removed
The report wizard should now look like this:
6 Click the button
Trang 587 When the Labeling fields screen appears, click the
button
Trang 59DATABASE BASICS
54
8 When the Grouping screen appears, click the button
Trang 609 When the Sort options screen appears, click the Sort by
drop-down arrow
Then click State in the list
10 Click the button
Trang 61DATABASE BASICS
56
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
Trang 62View 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
Trang 63
DATABASE BASICS
58
2 Click the button
The report is automatically created, saved and opened
It should look like this:
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
Trang 645 On the Menu Bar, click File, then Exit to close Base
Trang 65DATABASE BASICS
60
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 Rename the ID field (the Primary Key) Book ID
Trang 666 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
Trang 67DATABASE BASICS
62
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
Trang 6811 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
Trang 69DATABASE BASICS
64
15 Name the report Book Inventory
It should look like this:
16 Close the report
17 Exit OpenOffice.org Base
Trang 70Working 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
Trang 71WORKING WITH TABLES
66
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
Trang 723 When the Save As window appears, open the Practice Base
Files folder on your hard drive
Then click the button
4 Wait for the database to download completely, then close the
web browser
Trang 73WORKING WITH TABLES
68
Open an existing database
1 Start Base
2 When the Database Wizard opens, click the Open an existing
database file radio button
Trang 743 Click the button
Trang 75WORKING WITH TABLES
70
4 Open the Practice Base Files folder, then double-click
FlowerStore.odb
Trang 76The FlowerStore database window should now look like this:
Trang 77WORKING WITH TABLES
72
Adjust table layout
1 Double-click the Customers table to open it
Trang 782 Place your cursor on the divider between the Phone Number
and Fax Number column headings
The cursor should turn into a double-headed arrow:
Trang 79WORKING WITH TABLES
74
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
Trang 804 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
Trang 81
WORKING WITH TABLES
76
Create new tables
1 Click Create Table in Design view
A blank table will open in Design View:
Trang 822 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
Trang 83WORKING WITH TABLES
78
4 When the Save As window appears, type:
Orders
in the Table Name box
5 Click the button
6 When the alert window appears, click the button
Tip: You’ll assign a Primary Key later
Trang 84Specify 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
Trang 85WORKING WITH TABLES
80
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
Trang 86Assign 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
Trang 87WORKING WITH TABLES
82
4 In the Description column, type:
Date the order was placed
then press TAB
Trang 88Assign 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:
Trang 89WORKING WITH TABLES
84
3 On the Menu Bar, click File, then Save
Trang 90Specify 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
Trang 91WORKING WITH TABLES
86
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:
Trang 92
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
Trang 93WORKING WITH TABLES
88
Edit records
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
Trang 945 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:
Trang 95WORKING WITH TABLES
90
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