Access Lesson 01: Creating and Editing a Database10/29/2009
Lesson 1: Creating 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 a phone book, which is organized alphabetically by last name. databases, such the iTunes collection of obe navigated by hand. Large databases management system (DBMS), to help manage and retrieve information. whenever you use iTunes – searching tracks according to artist, album or genre playlists, for example. These lessons will introduce yoeasy to use, Microsoft Access.
Downloading Files for Lessons The files you need for this lesson are located at the URL below:
http://webs.wofford.edu/whisnantdm/Training/Access_200 You will see a list of files. Right-menu. Save the file to your H: drive
Database Concepts Access is structured in terms of tables that worksheet. Columns in the table, which are called in the table – Last Name, First Name, Middle Initial, Street, City, and State in the example shown below. Each row in the table, which particular item in the database – a particular person in the example shown below.
The data elements of a database at the intersection of a row (record) and a column (field) are called values. For example, the value of the First Name field foshown above is “Alfred.”
Access Lesson 01: Creating and Editing a Database 1
Microsoft Access
Lesson 1: Creating and Editing a Database
are collections of information that are organized so that you can easily find the It is fairly easy to retrieve information from small databases, such as
hone book, which is organized alphabetically by last name. On the other hand, ldatabases, such the iTunes collection of over 1.5 million tracks (in July 2005), are too massive to be navigated by hand. Large databases require a separate computer program, called a
to help manage and retrieve information. You are using a DBMS searching tracks according to artist, album or genre and
These lessons will introduce you to a DBMS that is accessible and fairly
Downloading Files for Lessons
The files you need for this lesson are located at the URL below:
/whisnantdm/Training/Access_2003/Files_For_Lessons/
-click on the first link and choose Save Target As .
H: drive. Repeat for the other files on the list.
Access is structured in terms of tables that have rows and columns and look a lot like ble, which are called fields, identify the types of data that are
Last Name, First Name, Middle Initial, Street, City, and State in the example in the table, which is called a record, is a set of information abo
a particular person in the example shown below.
The data elements of a database at the intersection of a row (record) and a column (field) are . For example, the value of the First Name field for the second record in the table
are collections of information that are organized so that you can easily find the from small databases, such as
On the other hand, large are too massive to
called a database
You are using a DBMS and creating
that is accessible and fairly
/Files_For_Lessons/
Save Target As . . . in the
look a lot like an Excel , identify the types of data that are stored
Last Name, First Name, Middle Initial, Street, City, and State in the example a set of information about a
a particular person in the example shown below.
The data elements of a database at the intersection of a row (record) and a column (field) are r the second record in the table
Access Lesson 01: Creating and Editing a Database 10/29/2009 2
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 Lesson 01: Creating and Editing a Database10/29/2009
Access is a relational database management system (RDBMS)
one table to store information. Each table a college student database might have one another showing the classes they are taking. These two tables have a relationship
by matching the two StudentID numbers we can see thHumanities 100, Math 200, and Religion 202 in the 200409 term. If a database contains a large number of fields, a oneunwieldy. Grouping data in multiple tables usually allows it 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
rather than later.
Question: Suppose you were storing the above data in one table rather than two
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.
enter a record for one term and then for another?
student taking five classes in a semester? Searching in several smaller tables also is can pull information from multiple tables.
Access Lesson 01: Creating and Editing a Database 3
relational database management system (RDBMS) that generally Each table holds data that are logically inter-related.
a college student database might have one table of personal information about students and another showing the classes they are taking.
relationship created by the matching StudentID numbers. ID 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
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
ppose you were storing the above data in one table rather than two
this lead to more work entering data and an increased chance of making
Think about Alfred E. Neumann, for whom class data is shown in both
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?
ing in several smaller tables also is more efficient because it is easy to createcan pull information from multiple tables.
uses more than related. For example,
table of personal information about students and
ID numbers. For example, Psychology 104,
table database will be very large and maintained and manipulated
NOTE: You will find these lessons interspersed with Questions and Practice Problems.
at the time you read them
ppose you were storing the above data in one table rather than two.
this lead to more work entering data and an increased chance of making
Think about Alfred E. Neumann, for whom class data is shown in both
What kind of duplication will be required when you
How would you store data for a
easy to create queries that
Access Lesson 01: Creating and Editing a Database 10/29/2009 4
Naming Conventions 1. Database Objects
We will use the Leszynski (Hungarian) naming convention
1 to name database objects in these lessons. This convention is used widely within the Microsoft Access community.
• The first three letters of the name are lowercase and identify the type of object
• The name following the prefix begins with a capital letter
• Names contain only letters and numbers with no spaces
Prefix Object Type Example
tbl Table tblEmployees
frm Form frmNameEntry
qry Query qryLastNames
rpt Report rptCitiesZips
2. Field Names
Field names should contain no spaces. A space between characters is represented by the under-score character (_). For example, instead of using “Class 1” as a field name, use “Class_1.” Some people prefer to use “CamelCase” in names – for example, “FirstName” instead of “First_Name.” Either form is acceptable, but it is best to be consistent within a single database.
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:
Label No. Artist A-side B-side Condition Value
Swan 4152 Beatles She Loves You I’ll Get You Excellent $150.00
Swan 4152 Beatles She Loves You I’ll Get You Fair $ 75.00
Swan 4152 Beatles She Loves You I’ll Get You Poor $ 10.00
Capitol 5555 Beatles We Can Work It Out
Day Tripper Good $ 50.00
Soma 1137 Fendermen Muleskinner Blues
Torture Good $8.50
Soma 1137 Fendermen Muleskinner Blues
Torture Fair $5.00
Decca 29791 Haley, Bill and the Comets
See You Later Alligator
The Paper Boy
Excellent $12.00
Mercury 71032 Platters I’m Sorry He’s Mine Fair $15.00
Volt 157 Redding, Otis (Sittin’ On) The Dock of the Bay
Sweet Lorene Good $6.50
1 Microsoft Corporation. Microsoft Official Academic Course: Microsoft Office Access 2003. Redmond, WA: Microsoft Press, 2004.
Access Lesson 01: Creating and Editing a Database10/29/2009
Notice the duplication in several fields in this tablerecords). To remove the duplications, 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.primary key field. We will add unique 45 rpm record that was issued. IDSpecific will identify a specific storing a word for the condition, wecondition, which will make data entry easier. tblIssue ID45 Label No. Artist
1 Swan 4152 Beatles
2 Capitol 5555 Beatles
3 Soma 1137 Fendermen
4 Decca 29791 Haley, Bill and the Comets
5 Mercury 71032 Platters
6 Volt 157 Redding, Otis
tblValue IDSpecific ID45 Condition Value
1 1 E
2 1 F
3 1 P
4 2 G
5 3 G
6 3 F
7 4 E
8 5 F
9 6 G
Question: Each row in the tbl
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.
When Access starts you will see a screen that looks something like this one.
Access Lesson 01: Creating and Editing a Database 5
duplication in several fields in this table (for example, in the first three Beatles . To remove the duplications, we will construct the database with more than one table. In
, 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
unique IDs as primary keys in the two tables. ID45 will identify a . IDSpecific will identify a specific copy you own.
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.
A-side
She Loves You
We Can Work It Out
Fendermen Muleskinner Blues
Haley, Bill and the Comets See You Later Alligator
I’m Sorry
Redding, Otis (Sittin’ On) The Dock of the Bay
Value
$150.00
$ 75.00
$ 10.00
$ 50.00
$8.50
$5.00
$12.00
$15.00
$6.50
Each row in the tblValue table is associated with a row in the tbl
What field in each table establishes the relationship between the two tables?
Having figured out the tables we need, we are ready icrosoft Office
When Access starts you will see a screen that looks
(for example, in the first three Beatles construct the database with more than one table. In
, one to store information about each 45 record and one to store at each table must have a
IDs as primary keys in the two tables. ID45 will identify a . Instead of
l use one letter (e.g., “E” for “Excellent”) to specify the
B-side
I’ll Get You
Day Tripper
Torture
The Paper Boy
He’s Mine
Sweet Lorene
table is associated with a row in the tblIssue table.
What field in each table establishes the relationship between the two tables?
Access Lesson 01: Creating and Editing a Database10/29/2009
Creating a New Database Click on File > New from the main menu Choose Blank database from the New File menu at the right. Navigate to your H: drive and save the database with the file name Records.
Creating Tables in Design View First we will create a table with the ID45 Label No. Artist
We will name the table tblIssue, but don’t have to specify a name until we save the design [see below].
Access Lesson 01: Creating and Editing a Database 6
m the main menu
from the New File menu at the right.
and save
in Design View
with the field names shown below.
A-side
, but don’t have to specify a name until we save the design [see
B-side
, but don’t have to specify a name until we save the design [see
Access Lesson 01: Creating and Editing a Database10/29/2009
We will create the table in Design View
when you want to work on the structure (schema) of your database and not the data stored in the database. database window, which you now should see, click on Tables in the Objects column on the left side of the window. Then double-click on Create table in Design v
on the Design icon. You then will see the Design View
new table. 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 storedfor 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. When you design a table, the first thing you do is to specify the Types – the type of data that is allowable for each field. A few common data types are listed below:
Data Type
Text (the default data type) Letters and numbers
Number Numbers
AutoNumber Numbers in sequautomatically created by Access
Currency Numbers
Date and time Numbers
Access Lesson 01: Creating and Editing a Database 7
Design View. Use this view work on the structure (schema) of your
database and not the data stored in the database. In the database window, which you now should see, click on
in the Objects column on the left side of the
Create table in Design view or click
Design View for the
lows you to enter in the table and to
A data type indicates the kind of data to be stored—
example, numbers, text, or dates. It is best to select the type that most closely matches the kinds of values you are
hen you design a table, the first thing you do is to specify the Field Names and the f data that is allowable for each field. A few common data types are listed
Allowable Field Values Number of C
Letters and numbers Up to 255
Numbers Up to 64,000
Numbers in sequence that are automatically created by Access
Numbers
Numbers
and the Data
f data that is allowable for each field. A few common data types are listed
Number of Characters
Up to 255
Up to 64,000
Access Lesson 01: Creating and Editing a Database10/29/2009
The first Field Name we will enter is ID45, the numbers we will use as primary keys to uniquely identify each record. Enter “ID45” as the first field name and change its AutoNumber. We need to specify that this field holds the primary key for the table. Right-click on the Field Name. In the menu that pops up, select Primary Key. When you do so, you should see a small key icon in the column to the left of the Field Name. Enter “Label” as the second field name. The default Data Type is Text, which is appropriate for this field. You will see a list of Field Properties
Design View window. The default Field Size for field is 50, which is much bigger than a record label name is ever going to be. Change the Field Size
Enter the other Field Names as shown at the right. as the lengths for Artist, A_Side and B When you have entered them, click on the the table.
Access Lesson 01: Creating and Editing a Database 8
we will enter is ID45, the numbers we will use as primary keys to uniquely identify each record. Enter “ID45” as
hange its Data Type to
We need to specify that this field holds the primary key for the table. click on the Field Name. In the menu that pops up, select
When you do so, you should see a small key icon in to the left of the Field Name.
Enter “Label” as the second field name. The default Data Type is Text, which is appropriate for this field.
Field Properties at the bottom of the Design View window. The default Field Size for a Text field is 50, which is much bigger than a record label name is
Field Size to 20.
Enter the other Field Names as shown at the right. Use 100 Side and B_Side.
ed them, click on the Save icon to save
Access Lesson 01: Creating and Editing a Database10/29/2009
In the Save As window that pops up, enter “tblIssue”name of the table and click on OK. To view the Database window again you can click on the Database Window icon in the main toolbar. You also can minimize the Table window by clicking on the Minimize icon in its upper right corner. The Database window will look the same as before except that tblIssue is now included in the list of tables in the database.
Exercise: Create a second table with the name “tblValue”
data on the condition and value of the records
• What would be the primary key?
• What would be appropriate Data Types for each field.
type you can specify the number of decimal places.
Adding Data to a Table Now that the tables have been created we need to populate them with data. We will start with tblIssue
name in the list of tables.
Access Lesson 01: Creating and Editing a Database 9
window that pops up, enter “tblIssue” as the name of the table and click on OK.
will look the same as before except that tblIssue is now included in the list of tables in the database.
reate a second table with the name “tblValue” with fields ready to hold the
data on the condition and value of the records (on page 4).
What would be the primary key?
What would be appropriate Data Types for each field. Note that in a Number
n specify the number of decimal places.
Now that the tables have been created we need to populate them tblIssue. Double-click on the table
with fields ready to hold the
Note that in a Number
Access Lesson 01: Creating and Editing a Database10/29/2009
This will display the Datasheet View
view in which you add data to the table.reminiscent of a spreadsheet. Each column is labeled by a field name. Enter the data in the table below into the database.is autonumbered. Every time you make an entry of a new Label, the next number will
automatically be added to the corresponding ID45 cell.
cell, pressing the Tab key will move to the next cell on t ID45 Label No. Artist
1 Swan 4152 Beatles
2 Capitol 5555 Beatles
3 Soma 1137 Fendermen
4 Decca 29791 Haley, Bill and the Comets
5 Mercury 71032 Platters
6 Volt 157 Redding, Otis
When you have entered the data, you may find that the column widths do not match the data in the fields. For example, the Label column is consistently wider than the Label names that have been entered. On the other hand the columns for the Artists’ names and song titles are too narrow.
Access Lesson 01: Creating and Editing a Database 10
Datasheet View of the table – the view in which you add data to the table. This view is reminiscent of a spreadsheet. Each column is labeled by a
Enter the data in the table below into the database. Don’t type anything in the ID45 field, which
. 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 key will move to the next cell on the right.
A-side
She Loves You
We Can Work It Out
Fendermen Muleskinner Blues
Haley, Bill and the Comets See You Later Alligator
I’m Sorry
Redding, Otis (Sittin’ On) The Dock of the Bay
When you have entered the data, you may column widths do not match
example, the Label column is consistently wider than the Label names that have been entered. On the other hand the columns for the Artists’ names and song titles are too
he ID45 field, which
. Every time you make an entry of a new Label, the next number will
When you have entered the data for one
B-side
I’ll Get You
Day Tripper
Torture
The Paper Boy
He’s Mine
Sweet Lorene
Access Lesson 01: Creating and Editing a Database10/29/2009
To match the width of the column to its data, move the cursor on the line thof one of the columns. When the cursor is positioned properly, it will appear as a line with two horizontal arrows, as illustrated above. Doublethe width of the column automatically
Save and Close (File > Close on the main menu) this table. Open the tblValue table and add the data shown here. The contents of the IDSpecific field should becannot be entered. Enter “E” for Excellent, “G” for Good, andtype the dollar sign for the monetary values. Save this table and close it.
Editing Data You can change the values stored in the database at any time. name of the Otis Redding A-side to be simply “The Dock of the Bay.” Open the tblIssue table and click on the cell containing “(Sittin’ On) The Dock of the Bay.” Delete the characters you do not want. Save the table when you are finished.
Access Lesson 01: Creating and Editing a Database 11
To match the width of the column to its data, move the cursor on the line that is the right border of one of the columns. When the cursor is positioned properly, it will appear as a line with two horizontal arrows, as illustrated above. Double-clicking with the cursor in this position will set the width of the column automatically.
on the main menu) this table.
table and add the data shown here. The should be autonumbered and
Enter “E” for Excellent, “G” for Good, and so forth. Do not type the dollar sign for the monetary values.
You can change the values stored in the database at any time. Suppose you decide you want the side to be simply “The Dock of the Bay,” rather than “(Sittin’ On)
table and click on the cell containing “(Sittin’ On) The Dock of the Bay.” elete the characters you do not want.
Save the table when you are finished.
at is the right border of one of the columns. When the cursor is positioned properly, it will appear as a line with two
clicking with the cursor in this position will set
Suppose you decide you want the The Dock of the Bay,” rather than “(Sittin’ On)
table and click on the cell containing “(Sittin’ On) The Dock of the Bay.”
Access Lesson 01: Creating and Editing a Database10/29/2009
Adding a Field Even if you have planned carefully in advance, it is not unusual to find you need to add a field once you actually start using the database. In our example, after using the Records database for while, you find that you need a field to show that datrecording. We will add this field to the tblValue table. Open tblValue. The table will open in Datasheet View. To add a field you need to be in Design View. Click on the Design View icon. In the Design View, enter a field with name “DatePurchased” and Date/Time type. Save the table. Now, click on the Datasheet View
Design View icon when you toggled to the Design View.
Access Lesson 01: Creating and Editing a Database 12
Even if you have planned carefully in advance, it is not unusual to find you need to add a field once you actually start using the database. In our example, after using the Records database for
you need a field to show that date on which you purchased each specific recording. We will add this field to the tblValue table.
. The table will open in Datasheet View. To add a field you need to be in Design View.
, enter a field with name “DatePurchased” and Date/Time type.
Datasheet View icon, which replaced the Design View icon when you toggled to the Design View.
Even if you have planned carefully in advance, it is not unusual to find you need to add a field once you actually start using the database. In our example, after using the Records database for a
e on which you purchased each specific
Access Lesson 01: Creating and Editing a Database10/29/2009
The Datasheet View will display the including the new DatePurchased contains no data.
Setting Field Properties Before entering data in the new field, we will set a few Field
Properties. Return to the Design View and select the Condition field name. Enter the Description and Field
Properties shown here. We will describe the function of these entries on the next page.
Access Lesson 01: Creating and Editing a Database 13
The Datasheet View will display the contents of the table, Purchased field, which currently
Field
We will describe the function of these entries
Access Lesson 01: Creating and Editing a Database10/29/2009
Field Description A Field Description, such as the one illustrated on the right, is entered in the Design In the Datasheet view, when you are entering data, the Field Description is displayed at the bottom of the when the cursor is located in that field.
Field Properties: Field Size We already have covered Field Size
design, you will see an alert warnchange, all but the first character of any value stored in that field will be deleted. Be careful when making design changes to tables that already contain data.
Question: What does specifying Field Size = 1 do?
Field Properties: Format Property The Format property specifies the way that data is displayed. It does not change the way that the data actually is stored in the database given in the table below:
Format Symbol Data Display
> All characters displayed as uppercase
< All characters displayed as lowercase
@ Every “@” requires a text character or space to be entered.
Access Lesson 01: Creating and Editing a Database 14
A Field Description, such as the one illustrated entered in the Design View.
In the Datasheet view, when you are entering data, the Field displayed at the bottom of the Access window
when the cursor is located in that field.
ield Size
Field Size. Set the field size for Condition to 1. When you save the ning you that data might be lost. When you proceed with the
change, all but the first character of any value stored in that field will be deleted. Be careful sign changes to tables that already contain data.
What does specifying Field Size = 1 do?
Property
specifies the way that data is displayed. It does not change the way that stored in the database – just how it is displayed. A few format example
Example
All characters displayed as uppercase If a field is formatted with “>”, data entered as “e” would be displayed as
All characters displayed as lowercase If a field is formatted with “as “G” would be displayed as “
Every “@” requires a text character or space to be entered.
If a field is formatted with “(@@@@@@@, data entered as 864be displayed as (864) 123useful for phone numbers, for instance.
to 1. When you save the ing you that data might be lost. When you proceed with the
change, all but the first character of any value stored in that field will be deleted. Be careful
specifies the way that data is displayed. It does not change the way that format examples are
If a field is formatted with “>”, data entered as “e” would be displayed as “E”
If a field is formatted with “<”, data entered ” would be displayed as “g”
If a field is formatted with “(@@@) @@@-@@@@, data entered as 8641234567 would be displayed as (864) 123-4567. This is useful for phone numbers, for instance.
Access Lesson 01: Creating and Editing a Database10/29/2009
Choosing the Format = “>” for the Condition field displayed as uppercase. Then you don’t have to worry so much about‘e’ as the condition. For some data types, you can choose a format property from a list. For example, move to the Datea Date/Time Data Type. If you click on the white rectangle nexan icon appear. Clicking on this icon will display a list of date formats from which to choose. For our example, choose Medium Date, which will display the dates like “19-Jun-94.” Go into Datasheet View and enter dates in the empty fields. Notice that dates always are displayed in Medium Date format (e.g., 1994) even if you enter the date in another format (e.g., 6/19/94).
Access Lesson 01: Creating and Editing a Database 15
for the Condition field means that all entries in that field will be Then you don’t have to worry so much about whether you enter “E” or
choose a format property from a . For example, move to the DatePurchased field, which has
white rectangle next to Format, you will see
Clicking on this icon will display a list of date formats from which to choose. For our example, choose Medium Date, which will display the
Go into Datasheet View and enter dates in the ds. Notice that dates always are
displayed in Medium Date format (e.g., 19-Jun-94) even if you enter the date in another format
field will be whether you enter “E” or
Access Lesson 01: Creating and Editing a Database10/29/2009
Field Properties: Validation Rule and Text Databases often include Validation Rules
you make an entry in a field, Access checks your entry against the validation rule (if any) that has been set up for that field. If the entry agrees with the rule, then everything is OK. If the entry violates the validation rule, an error message will be displayed showing the validation text. For example, the only entries possible in the Conditions field are E, G, F, or P. The validation rule shown at the right limits entries to these four letters.
Practice: Enter this rule and the g
“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 taDatePurchased column of tblValue tCondition columns. In Datasheet View, click on the Field Label (DatePurchased) so that the entire column is selected. “Grab” the column by clicking on the Field Label and holding the left mouse key down. Drag the column to the left until a solid line is displayed where you want to drop the column.
Access Lesson 01: Creating and Editing a Database 16
Validation Rule and Text
Validation Rules that limit the input that is possible in a field. When you make an entry in a field, Access checks your entry against the validation rule (if any) that has been set up for that field. If the entry agrees with the rule, then everything is OK. If the entry
rule, an error message will be displayed showing the validation text.
For example, the only entries possible in the Conditions field are E, G, F, or P. The validation rule shown at the right limits entries to these four letters.
ule and the go to the Datasheet View of the table and try
“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”?
atabase 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
column of tblValue two columns to the left so that it is between the ID4
click on the Field Label Purchased) so that the entire column is selected.
rab” the column by clicking on the Field Label and holding the left mouse key down. Drag the column to the
line is displayed where you want to drop
at is possible in a field. When you make an entry in a field, Access checks your entry against the validation rule (if any) that has been set up for that field. If the entry agrees with the rule, then everything is OK. If the entry
rule, an error message will be displayed showing the validation text.
to the Datasheet View of the table and try to enter
atabase for a while, you may decide to change the position of one of the Suppose, for example, that you want to move the
columns to the left so that it is between the ID45 and
Access Lesson 01: Creating and Editing a Database10/29/2009
Drop the column in the new position by releasing the mouse button.
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 thoughinformation from every record in the database
a field in case you want to restore it later.
field. Let’s delete the DatePurchased field from tblValue. Select the entire column by clicking on the Field Label. Right-click on the column. In the popappears, click on Delete Column
Access will ask you if you really want to do something this drastic. Click on Yes to delete the field. Save the database.
Access Lesson 01: Creating and Editing a Database 17
Drop the column in the new position by releasing the
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
Purchased field from tblValue. Select the entire column by clicking on the Field Label.
click on the column. In the pop-up menu that Delete Column.
ill ask you if you really want to do something this drastic.
If you find that you never use a field in the database, you may decide to delete it. This only deleting a field deletes this
Always back up your database before deleting
ndo to undo the deletion of a
Access Lesson 01: Creating and Editing a Database10/29/2009
Deleting a Record At some point, you probably will want to remove one or more records from the database example, you sell one of the 45s in your collection. restored without re-entering the data
in case you want to restore it later. Open tblIssue. Suppose that you have sold the Platters record and want to remove it from the database. Click somewhere in the row containing this record and then click on the Delete Record icon. You will be asked to confirm that you really want to do this. 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 soldbeen sold. If a sold-date value is null (not present), then the 45 has lets you keep a history of your collection. Consider such alternatives when you design a database.
Print Preview and Printing a Page
Open tblIssue, if it is not already open. To preview what the printed version of the table will look like, click on the Print Preview icon.
Access Lesson 01: Creating and Editing a Database 18
At some point, you probably will want to remove one or more records from the database of the 45s in your collection. Once a record has been deleted it cannot be
entering the data. Always back up your database before deleting a record
in case you want to restore it later.
You will be asked to confirm that you really want to do
native 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
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
and Printing a Page
At some point, you probably will want to remove one or more records from the database – if, for Once a record has been deleted it cannot be
. Always back up your database before deleting a record
native to deleting a record for a 45 you no longer have, you could add a field that date value is present in a row, then that record has
not been sold yet. This design lets you keep a history of your collection. Consider such alternatives when you design a
Access Lesson 01: Creating and Editing a Database10/29/2009
You probably will see something like the picture at the right. Note that all of the table does not fit on the page. We need to change the page setup. Click on the Setup button or select File > Page Setup from the main menu. In the Page Setup window, select the Page tab and Landscape orientation. Click on OK. This will orient the page so that the entire table will be displayed on one page. Although we will not do this as part of thiclicking on the Print icon.
More About Field Properties Save and Close the Records databasedownloaded into your H: drive. You will see that this database has only one table, tblEmployees. Open this table.
Access Lesson 01: Creating and Editing a Database 19
In the Page Setup window, select the Page tab and Landscape
This will orient the page so that the entire table will be displayed on one
Although we will not do this as part of this lesson, you can print a table by
More About Field Properties
Save and Close the Records database. Open the database named “ExampleDB” that youthat you
Access Lesson 01: Creating and Editing a Database10/29/2009
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
Field Properties: Default Value In this table, we see that most of the states are SC. Choose the State and enter “SC”. When a default value, such as “SC,” is set this value will automatically be entered when a new record is created. It can be changed if need be. Also set State’s Format property to “>”.
Question: What does setting the format property to “>” Finally enter the description “Enter the two
Field Properties: Input Mask An Input Mask lets you designate the way dmay be entered for a particular field, reducing the probability of data input errors. Input Mask property is different from the Format
property.
• The Input Mask property limits the way that data can be entered and hence defines the way that data actually exists in
• The Format property limits the way that data is displayed – not how it is stored.
Let’s use an input mask to designate how phone numbers may exist in the table. In Design View, select the Home Phone field and click on tInput Mask property.
Access Lesson 01: Creating and Editing a Database 20
and set the text Field Sizes to those shown below:
Default Value
hat most of the states are SC. Choose the Default Value field property for and enter “SC”. When a default value, such as “SC,” is set this value will automatically be
entered when a new record is created. It can be changed if need be.
e’s Format property to “>”.
: What does setting the format property to “>” do?
ter the two-letter abbreviation” for the State field.
put Mask
lets you designate the way data may be entered for a particular field, thereby reducing the probability of data input errors. The
Input Mask property is different from the Format
property limits the way that data can be entered and hence defines
t data actually exists in a table.
property limits the way that not how it is stored.
to designate how phone . In Design View,
field and click on the
field property for and enter “SC”. When a default value, such as “SC,” is set this value will automatically be
for the State field.
Access Lesson 01: Creating and Editing a Database10/29/2009
You will see a small button with three dots displayed at the right of the Input Mask row. Click on this button. You will be asked if you want to save the table first. Click on
In the Input Mask Wizard window, selecNumber input mask. The appearance that this mask will give to the data is shown in the Data Look column. Using this input mask, phone numbers will look like (206) 555-1212. Click on Next. The following window, you will be asked if you want to change anything. Let’s not change anything. Click on Next again. You next will be asked if you want the stored data to include the symbols in the mask. This is useful in the case of phone numbers, so let’s do it. Select the top option. Click on Next and then Finish. The expression for this Input Mask now is displayed. 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.
Access Lesson 01: Creating and Editing a Database 21
You will see a small button with three dots displayed at the right of the Input Mask row. Click on
You will be asked if you want to save the table first. Click on Yes.
Input Mask Wizard window, select the Phone
input mask. The appearance that this mask will give to the data is shown in the Data Look column. Using this input mask, phone numbers will look like
The following window, you will be asked if you want to change anything. Let’s not change anything. Click
You next will be asked if you want the stored data to include the symbols in the mask. This is useful in the case of phone numbers, so let’s do it.
The expression for this Input Mask now is displayed.
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.
You will see a small button with three dots displayed at the right of the Input Mask row. Click on
the database and look back at the Datasheet View, you will see that the phone
Access Lesson 01: Creating and Editing a Database10/29/2009
Enter a new record or two in the table to see how the Input Mask works. Note: As an alternative, you could choose not to have the symbols in the mask stored in the database and instead use a format to describe how they are to be displayed. The advantage of thalternative design is that you can change the format later. For example, many people are starting to display phone numbers with periods instead of parentheses, spaces, and dashes.
Field Properties: Captions It is useful to give fields names that do Although Access allows field names with spaces, not all DBMS do. It also is easier to write SQL spaces (more of this in Lesson 5). On the other hand, people are accustomed to seeing spaces between words, label columns in tables with spaces included. We can do this by defining captions for fields. Define a caption for fields that need spaces between words LastName for example, for which the caption is If you look at the Datasheet View, you will see the captions displayed at the top of the columns rather than the actual field names.
Access Lesson 01: Creating and Editing a Database 22
r a new record or two in the table to see how the Input Mask works.
As an alternative, you could choose not to have the symbols in the mask stored in the database and instead use a format to describe how they are to be displayed. The advantage of thalternative design is that you can change the format later. For example, many people are starting to display phone numbers with periods instead of parentheses, spaces, and dashes.
Field Properties: Captions
ames that do not include spaces. Although Access allows field names with spaces, not all DBMS
SQL statements if you don’t include ). On the other hand, people are
accustomed to seeing spaces between words, so we would like to label columns in tables with spaces included. We can do this by
Define a caption for fields that need spaces between words – xample, for which the caption is “Last Name.”
k at the Datasheet View, you will see the captions displayed at the top of the columns rather than the actual field names.
As an alternative, you could choose not to have the symbols in the mask stored in the database and instead use a format to describe how they are to be displayed. The advantage of the alternative design is that you can change the format later. For example, many people are starting to display phone numbers with periods instead of parentheses, spaces, and dashes.
k at the Datasheet View, you will see the captions displayed at the top of the columns
Access Lesson 01: Creating and Editing a Database10/29/2009
Review: Creating a Table Create a new table in the example databasefirst field, the primary key, will containnamed “DeptName,” will contain text. Make the entries shown below in 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
Importing Records into a Database When creating a database, it may be that some of the data you need already exists spreadsheet, for example. If this is the case, you probably will want to import the existing data into your database to avoid entering it agai In our example, suppose that information about salaries and whether employees are exempt from receiving overtime pay is stored in an Excel spreadsheet named into your H: drive.. We want to create a new table in the database from the Excel spreadsheet. if it is not already open. Select File > Get External Data
main menu.
Access Lesson 01: Creating and Editing a Database 23
in the example database named tblDepartments, that contains two fields. The field, the primary key, will contain numbers. Name this field “DeptID.” The
,” will contain text. Make the entries shown below in the table.
Information Technology
Importing Records into a Database
When creating a database, it may be that some of the data you need already exists et, for example. If this is the case, you probably will want to import the existing data
into your database to avoid entering it again by hand.
In our example, suppose that information about salaries and whether employees are exempt from e pay is stored in an Excel spreadsheet named Salaries. You download
We want to create a new table in the ExampleDB database from the Excel spreadsheet. Open ExampleDB
ata > Import… from the
, that contains two fields. The ID.” The second field,
,” will contain text. Make the entries shown below in the table. Save the table.
When creating a database, it may be that some of the data you need already exists – in an Excel et, for example. If this is the case, you probably will want to import the existing data
In our example, suppose that information about salaries and whether employees are exempt from ownloaded this
Access Lesson 01: Creating and Editing a Database10/29/2009
Import the Microsoft Excel file named “Salaries” from your H: driveYou will probably need to changesetting of the “Files of type:” list at the bottom of the Import Spreadsheet Wizard to find your Excel file. The spreadsheet has three worksheet tabs, so Access will ask you which one you want to use. We will use the first sheet, which is the only one that contains data. Click on Next. You will be asked if you want to use the Excel column headings as Field Names
you create. In this example, we do.careful to use names that meet our naming conventions for fields.) Click on Next.
Access Lesson 01: Creating and Editing a Database 24
the Microsoft Excel file your H: drive.
change the list at the
bottom of the Import Spreadsheet
The spreadsheet has three worksheet tabs, so Access will ask you which one you want to use. We will use the first sheet, which is the only one that contains
ou will be asked if you want to use the Excel Field Names in the table
you create. In this example, we do. (We were careful to use names that meet our naming
Access Lesson 01: Creating and Editing a Database10/29/2009
We want this to be a new table. Click on Next. We will use the Employee ID field as a Primary Key, so we do not want it to have any duplicates. Choose Indexed with No Duplicates. Click on Next. We will use the Employee ID as the for the table. Click on Next.
Access Lesson 01: Creating and Editing a Database 25
ployee ID field as a Primary Key, so we do not want it to have any duplicates. Choose
as the Primary Key
Access Lesson 01: Creating and Editing a Database10/29/2009
Finally, enter the name of the table tblSalaries. You now will see tblSalaries included in the list of tables in the database. Finally, add captions to the Field Properties of tblDepartments and tblSalaries as needed. Save the database.
Exercises
1. What is the difference between the Datasheet and Design Views in Access? What do you
use the Design View for? What about the Datasheet View? Where is the icon on the Access
toolbar that toggles you back and forth between these tw
2. What is a primary key in a table? Why is it necessary?
3. How is a RDBMS different from a DBMS?
4. What is the purpose of the Autonumber format?
5. What is the difference between a field description and a validation rule? How is each used
in Access?
Access Lesson 01: Creating and Editing a Database 26
of the table – let’s call it
You now will see tblSalaries included in
to the Field and
1. What is the difference between the Datasheet and Design Views in Access? What do you
use the Design View for? What about the Datasheet View? Where is the icon on the Access
toolbar that toggles you back and forth between these two views?
2. What is a primary key in a table? Why is it necessary?
3. How is a RDBMS different from a DBMS?
4. What is the purpose of the Autonumber format?
5. What is the difference between a field description and a validation rule? How is each used
1. What is the difference between the Datasheet and Design Views in Access? What do you
use the Design View for? What about the Datasheet View? Where is the icon on the Access
5. What is the difference between a field description and a validation rule? How is each used
Access Lesson 01: Creating and Editing a Database 10/29/2009 27
6. Look at the table of data below:
City State Office Phone Staff
Chicago IL Cicero (773) 613-4228 Bill Jones
Chicago IL Cicero (773) 613-4228 Jill Kirby
Chicago IL Cicero (773) 613-4228 Jon Gaff
Chicago IL Oak Park (773) 888-1943 Mary Arthur
Chicago IL Oak Park (773) 888-1943 Virginia Dawes
Chicago IL Oak Park (773) 888-1943 Alfred Prufrock
Chicago IL Berwyn (773) 762-3333 Tillie Mays
Chicago IL Berwyn (773) 762-3333 John Illkie
Chicago IL Berwyn (773) 762-3333 Kirby Puck
Chicago IL Addison (773) 784-3276 Jonica Kinsey
Chicago IL Addison (773) 784-3276 Bubba Ames
Chicago IL Addison (773) 784-3276 Chris Armstrong
Atlanta GA Doraville (404) 749-1885 Otto Engine
Atlanta GA Doraville (404) 749-1885 Frank Hucks
Atlanta GA Doraville (404) 749-1885 Linda Dyson
Atlanta GA Roswell (404) 559-1144 Juanita Masters
Atlanta GA Roswell (404) 559-1144 Aaron James
Atlanta GA Roswell (404) 559-1144 David Demster
Atlanta GA Downtown (404) 622-6434 R. K. Lings
Atlanta GA Downtown (404) 622-6434 Reba Newling
Atlanta GA Downtown (404) 622-6434 Watts Yterby
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.