Vous êtes sur la page 1sur 39

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

Modify tables
1. Copy FoodStore1 at \\10.0.71.14\Exercises\Jerame\BUS IT 2\Access
Exercises\Misc.

2. Paste it in your home folder under Practice Access Files folder. Filename
must still be FoodStore1.

Open an existing database


1. Start Microsoft Access.
2. In the Open Recent Database pane, click More...

3. Open the Practice Access Files folder, then double-click FoodStore1.


The FoodStore1 database window should now look like this:

Employ an input mask


1. In the Navigation Pane, click the arrow down next to forms and choose
Tables.

(Note: No need to do this if Tables is already the default view in your


navigation pane.)
Right-click the Customers table.

2. When the menu appears, click Design View.

The Customers table should open in Design View.

3. Click in the Phone Number row.

4. In the Field Properties area of the window, click in the Input Mask property.

5. Click the

button beside the Input Mask property.

6. When the Input Mask Wizard window appears...

...make sure the Phone Number input mask is selected.


Then click in the Try It: box.
7. In the Try It box, type:
2125551515

8. Click the

button.

9. When the next screen appears, click the

button.

10. When the next screen appears, click the radio button beside With the
symbols in the mask, like this.

Then click the

button.

11. When the final screen appears, click the

button.

The Input Mask for the Phone Number field should now look like this:

12. In the Ribbon, click View, then Datasheet View.

13. When the alert window appears, click the


Customers table.

14. Close the Field List pane.

button to save the

15. Use the TAB key to move across the first record until you are in the Phone
Number field.

16. Type:
3015551212

17. Press the TAB key four times to move to the next record.
The new phone number has been saved.
18. Save the Customers table, then close it.

Adjust table layout


1. Double-click the Customers table to open it.

2. Place your cursor on the divider between the Company Name and Address
1 column headings.

The cursor should turn into a double-headed arrow:

3. Double-click.
The Company Name 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.
4. Double-click the divider between the Address 1 and Address 2 column
headings.
The Address 1 field should resize to fit the data in it.
5. Close the Customers table.
6. When the alert window appears, click the

Create new tables


1. Click the Create tab.
In the Ribbon, click Table Design.

A blank table will open in Design View:

button to save changes.

2. In the first box in the Field Name column, type:


Order ID
then press the TAB key.
It should look like this:

3. In the Title Bar, click the

icon.

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.

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 AutoNumber.

2. 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


information is supposed to be stored in a field.

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.

4. In the Description column, type:


Date the order was placed
then press TAB.

Employ the Lookup Wizard


What does the Lookup Wizard do?
The Lookup Wizard allows you to create a field where database users can choose
from a list of things.
This list can come from a table or query, or list items can be specified manually.
1. In the Field Name column, type:
Customer
then press TAB.
2. In the Data Type column, click the down arrow, then Lookup Wizard...

3. When the Lookup Wizard appears, click the I want the lookup column to
look up the values in a table or query radio button.

Then click the

button.

4. Click the Customers table, then click the

button.

5. When next screen appears, double-click First Name.

6. Double-click Last Name.

7. Click the

button.

8. Click the first drop-down arrow, then Last Name.

9. Click the

button.

The Lookup Wizard should show how the field will look with data in it:

10. Click the

button.

11. In the label box, type:


Customer Name

Then click the

button.

12. When the alert window appears, click the

13. In the Description column, type:


Name of the customer who placed the order
then press TAB.
14. In the title bar, click the

icon.

The Orders table should look like this:

15. In the Ribbon, click View, then Datasheet View.

button.

The table should change to Datasheet View:

16. Click in the Customer Name field, then click the drop-down arrow.
A list of customers should appear:

17. In the Ribbon, click View, then Design View.

The table should change back to Design View:

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:

3. Save the table.

Specify field properties


1. Click in the Order Date field.

2. In the Field Properties section of the window, click in the Format box.

3. Click the drop-down arrow at the end of the box.

4. In the menu of formats that appears, click Short Date.

5. Save the table.


6. In the Ribbon, click View, then Datasheet View.
The table should look like this:

7. Close the table.

Edit records
1. Open the Customers table.
Make sure it's displayed in Datasheet View.
2. Click inside the Address 1 field for record number 3, between the two 5s in
35546 York Ave.

3. Press the BACKSPACE key on your keyboard.


The first 5 in the address should be gone:

4. Press TAB to move to the next field.


5. Type:
Unit L
It should replace the previous text:

Delete records
1. Right-click the row heading for Chris Happ's record.
2. In the menu that appears, click Delete Record.

3. When the alert window appears, click the

button.

TIP: Once a record has been deleted from the database, it cannot be
recovered. There is no Undo feature in Access.

Find records
Navigate records
1. In the Customers table window, click the

icon.

The last record in the database should be highlighted:

2. Click the

icon.

The sixth record should be highlighted.


3. Click the

icon again.

The fifth record should be highlighted.


4. Click the

icon.

The first record should be highlighted.


5. Click the

icon.

The second record should be highlighted.


6. Click the

button.

The Customers table should look like this:

Search for records


1. Click the Company Name column header.

The table should look like this:

Search for records


1. In the Ribbon, click Find.

2. When the Find and Replace window appears, type:


BBC
in the Find What box.

3. In the Match list, click the drop-down arrow, then Any Part of Field.

4. Click the

button.

The Customers table should now look like this, with BBC highlighted:

5. In the Find and Replace window, click the

button.

Sort and filter records


Sort in ascending order
1. Click the State column header.

2. In the Ribbon, click the

icon.

The Customers table should now look like this, with the States arranged in
ascending alphabetical order:

Sort in descending order


1. Click the Customer ID column header to highlight the column.

2. In the Ribbon, click the

icon.

The Customers table should now look like this, with the Customer ID
numbers arranged in descending order:

Filter records
1. Click in the State field for customer number 1.

Notice that the State is Florida.

2. In the Ribbon, click Selection, then "Equals FL".

The Customers table should now look like this, showing all customers
whose State is Florida:

3. In the Ribbon, click Toggle Filter.

The Customers table should show its original contents:

4. Close the table.


5. When the alert window appears, click the

button.

When should you 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.

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 Address
John

Elm St.

Jane

Oak St.

The Math Class table holds information about the students in math class:

Math Class
Student Name Grade
John

Jane

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

Math Class

Student Name Address Student Name Grade


John

Elm St. John

Jane

Oak St. Jane

Examine current table relationships


1. Click the Database Tools tab.

2. In the Ribbon, click Relationships.

3. In the Ribbon, click Show Table.

4. When the Show Table window appears, double-click Customers.

The Customers table should appear in the Relationships field:

5. In the Show Table window, double-click Employees.


The Employees table should appear in the Relationships field:

6. Double-click Order Details.


7. Double-click Orders.
8. Double-click Products.
9. In the Show Tables window, click the

button.

The Relationships field should now look like this:

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.

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.

5. Release the mouse button.


When the Edit Relationships window appears, click the

button.

The Relationships field 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. Close the Relationships window.
7. When the alert window appears, click the

8. Exit Microsoft Access.

button.

Vous aimerez peut-être aussi