Beruflich Dokumente
Kultur Dokumente
Databases are collections of information that are organized so that you can easily find the
information that you need. It is fairly easy to retrieve information from small databases, such as
a phone book, which is organized alphabetically by last name. On the other hand, large
databases, such the iTunes catalog of over 5 million songs (July 31, 2007), are too massive to be
navigated by hand. Large databases require a separate computer program, called a database
management system (DBMS), to help manage and retrieve information. You are using a DBMS
whenever you use iTunes – searching tracks according to artist, album or genre and creating
playlists, for example. These lessons will introduce you to a DBMS that is accessible and fairly
easy to use, Microsoft Access.
http://webs.wofford.edu/whisnantdm/Training/Access_2007/Files_For_Lessons/
You will see a list of files. Right-click on the first link and choose Save Target As . . . in the
menu. Save the file to your H: drive. Repeat for the other files on the list.
Database Concepts
Access is structured in terms of tables that have rows and columns and look a lot like an Excel
worksheet. Columns in the table, which are called fields, identify the types of data that are stored
in the table – Last Name, First Name, Middle Initial, Street, City, and State in the example
shown below. Each row in the table, which is called a record, is a set of information about a
particular item in the database – a particular person in the example shown below.
One of the fields, called the primary key, in a table uniquely identifies each of the records. In
the example shown above, the primary key is the ID. No two rows in a table can have the same
value in a primary key field.
Access is a relational database management system (RDBMS) that generally uses more than
one table to store information. Each table holds data that are logically inter-related. For example,
a college student database might have one table of personal information about students and
another showing the classes they are taking.
These two tables have a relationship created by the matching StudentID numbers. For example,
by matching the two StudentID numbers we can see that Bat Masterson took Psychology 104,
Humanities 100, Math 200, and Religion 202 in the 200409 term.
If a database contains a large number of fields, a one-table database will be very large and
unwieldy. Grouping data in multiple tables usually allows it to be maintained and manipulated
more efficiently.
NOTE: You will find these lessons interspersed with Questions and
Practice Problems. These are integral parts of the lessons and should be
done at the time you read them rather than later.
Would this lead to more work entering data and an increased chance of making
errors? (Hint: Think about Alfred E. Neumann, for whom class data is shown in both
the 200409 and 200502 terms.) What kind of duplication will be required when you
enter a record for one term and then for another? How would you store data for a
student taking five classes in a semester?
Searching in several smaller tables also is more efficient because it is easy to create queries that
can pull information from multiple tables.
A Database Example
Let’s assume that your hobby is collecting old 45 rpm records from the classic rock era of the
50s and 60s. You decide to create a database to help you manage your collection. We will create
an Access database to store the following information about your collection:
Notice the duplication in several fields in this table (for example, in the first three Beatles
records). To remove the duplications, we will construct the database with more than one table. In
this case we will use two tables, one to store information about each 45 record and one to store
information about the copies of that record that you have... Recall that each table must have a
primary key field. We will add unique IDs as primary keys in the two tables. ID45 will identify a
45 rpm record that was issued. IDSpecific will identify a specific copy you own. Instead of
storing a word for the condition, we will use one letter (e.g., “E” for “Excellent”) to specify the
condition, which will make data entry easier.
tblValue
IDSpecific ID45 Condition Price
1 1 E $150.00
2 1 F $ 75.00
3 1 P $ 10.00
4 2 G $ 50.00
5 3 G $8.50
6 3 F $5.00
7 4 E $12.00
8 5 F $15.00
9 6 G $6.50
In Class Question: Each row in the tblValue table is associated with a row in the
tblIssue table. What field in each table establishes the relationship between the two
tables?
Opening Access
Having figured out the tables we need, we are ready to create our database. Open Microsoft
Office Access.
In the Blank Database section that appears on the right side of the
screen, click on the Folder icon to choose where you want to save
the database.
Click on OK.
You should see the File Name Records.accdb, with H:\ below it.
Click on Create.
You now should see the Design View of the table – the view we use when we want to work on
the structure of the database, as opposed to the data stored in the database. The Design View
allows you to enter names of the fields in the table and to specify their data types. A data type
indicates the kind of data to be stored—for example, numbers, text, or dates. It is best to select
the type that most closely matches the kinds of values you are storing in a field.
The new field probably will be designated as the primary key for the
table – see if there is a small key icon to the left of the field name.
If the ID45 field has not been designated as the primary key, right-
click on the Field Name. In the menu that pops up, select Primary
Key.
The Home tab should be selected. If it is not, click on the Home tab to select it.
Enter the data in the table below into the database. Don’t type anything in the ID45 field, which
is autonumbered. Every time you make an entry of a new Label, the next number will
automatically be added to the corresponding ID45 cell. When you have entered the data for one
cell, pressing the Tab key will move to the next cell on the right.
Add the data shown at the right to the table. The contents of the
IDSpecific field should be autonumbered and cannot be entered.
Enter “E” for Excellent, “G” for Good, and so forth. Do not
type the dollar sign for the monetary values – because the Data
Type for this field is Currency, the dollar sign should be
displayed automatically,
Editing Data
You can change the values stored in the database at any time. Suppose you decide you want the
name of the Otis Redding A-side to be simply “The Dock of the Bay,” rather than “(Sittin’ On)
The Dock of the Bay.”
In the tblIssue table, click on the cell containing “(Sittin’ On) The Dock of the Bay.” Delete the
characters you do not want.
Field Description
The Field Description gives
the user information about
what kind of data may be
entered in that field.
Choosing the Format = “>” for the Condition field means that all entries in that field will be
displayed as uppercase. Then you don’t have to worry so much about whether you enter “E” or
‘e’ as the condition.
In Class Practice: In Design View, enter the validation rule shown above
• Go to the Datasheet View of the table and try to enter “B” for “Bad” as a
Condition.
• Does “B” satisfy the Validation Rule set up for this field?
• What role does the validation text play when you enter “B”?
Moving a Field
After using the database for a while, you may decide to change the position of one of the
columns or to remove it entirely from the table. Suppose, for example, that you want to move the
DatePurchased column of tblValue two columns to the left so that it is between the ID45 and
Condition columns.
Deleting a Field
If you find that you never use a field in the database, you may decide to delete it. This only
should be done after giving the deletion careful thought, because deleting a field deletes this
information from every record in the database. Always back up your database before deleting
a field in case you want to restore it later. You cannot use Edit, Undo to undo the deletion of a
field.
Click on Yes.
Note: as an alternative to deleting a record for a 45 you no longer have, you could add a field
that designates the date a record is sold. If a sold-date value is present in a row, then that
record has been sold. If a sold-date value is null (not present), then the 45 has not been sold
yet. This design lets you keep a history of your collection. Consider such alternatives when you
design a database.
Although we will not do it in this lesson, you could now choose Print on the Office Button to
print out a hardcopy of the table.
Change to Design View and set the text Field Sizes to those shown below:
• LastName 25
• FirstName 25
• MI 1
• Street 25
• City 25
• State 2
Because you have decreased some of the field sizes, you will be warned that data might be lost.
The field sizes above are more than sufficient to hold the data, so do not be concerned about this
warning.
In Class Question: What does setting the format property to “>” do?
• The Input Mask property limits the way that data can be entered and hence defines the
way that data actually exists in a table.
• The Format property limits the way that data is displayed – not how it is stored.
Click on Next.
If you Save the database and look back at the Datasheet View, you will see that the phone
numbers now are stored in the format specified by the Input Mask.
Enter a new record or two in the table to see how the Input Mask works.
The second field, named “DeptName,” will contain text. Make the entries shown below in the
table. Save the table.
DeptID DeptName
100 Purchasing
101 Finance
102 Shipping
103 Sales
104 Personnel
105 Marketing
106 Security
107 Engineering
108 Communications
109 Information Technology
In our example, information about salaries and whether employees are exempt from receiving
overtime pay is stored in an Excel spreadsheet named Salaries, which you downloaded into your
H: drive. We want to create a new table in the ExampleDB database from the Excel spreadsheet.
Click on Next.
Click on Next.
Click on Next.
Click on Next.
Click on Finish.
Finally, add captions to the Field Properties of tblDepartments and tblSalaries as needed.
5. What is the difference between a field description and a validation rule? How is each used
in Access?
How many Access tables would you set up to store this data efficiently? Decide on the fields
you would use in each table. What would be the primary key in each table? What would be the
relationships that link the tables?
7. You enter “Elmer Fudd” in a field that has the “<” Format. In what form will this name be
displayed on the screen? In what form will it actually exist in the database?
8. You enter “Elmer Fudd” in a field that has the “<” Input Mask. In what form will this
name be displayed on the screen? In what form will it actually exist in the database?
9. Define a format mask for a field that contains a nine-digit phone number so that the value
displays as 999.999.9999.