Access - Tables, Queries, Maintenance

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

University of Technology

IT Practical

Microsoft Access?
The term database describes a collection of data organized in a manner that allows
access, retrieval, and use of that data. A database management system, allows you to use
a computer to create a database; add, change, and delete data in the database; sort the data
in the database; retrieve data in the database and reports using the data in the database.
The database management system tool in this case is Microsoft Access. This is the
structure:

Database File: This is your main file that encompasses the


entire database and that is saved to your hard-drive or
floppy disk.
Example) StudentDatabase.mdb
Table:A table is a collection of data about a specific topic.
There can be multiple tables in a database.
Example #1) Students
Example #2) Teachers
Field:Fields are the different categories within a Table.
Tables usually contain multiple fields.
Example #1) Student LastName
Example #2) Student FirstName

Datatypes:Datatypes are the properties of each field. A


field only has 1 datatype.
FieldName) Student LastName
Datatype) Text

An Access database consists of a collection of tables. Once you have created the
database, you must create each of the tables within it. To create a table, you describe the
structure of the table to Access by describing the fields within the table. For each field,
you indicate the following:

1. Field name – each field in the table must have a unique name, e.g. id number
in the student table.
2. Data type – data type indicates to Access the type of data the field contain.
Can be either text, number, currency etc, depending on data arrangement
3. Description – A detailed description of the field is given.

1
Creating Tables
To Create a Table – Select the CREATE Ribbon

There are different ways to produce a table in Microsoft Access: (Create


Table, Create Table Template and Create Table Design)

1. The Create Table option gives the option to design and enter data all at
once. All design features are not taken care of immediately however.

2. The Create Table Template option provides already existing fields that
may or may not be required.

3. The Create Table Design deals with all the possible design elements.
Under the Create Table Design option(recommended)

To Define the Fields in the Table

1. Type the data for the Field Name column and then press the TAB key. The
word, Text, one of the possible data types(default data type) currently
displays. The arrow in the data column indicates a list of data types are
available.

2. If the item is a unique identifier enter (Primary Key) as the description and
then point to the Primary Key button on the Database window toolbar.

Saving a Table

The table structure is now complete. The final step is to save the table within the
database. At this time you should give the table a name and proceed to save.

Adding Records to a Table

Creating a table by building the structure and saving the structure is the first step in a
two-step process. The second step is to add records to the table. To add records to a table,
the table must be opened. You may often add records in phases. To add simply double-
click on newly-created table.

Creating Additional Tables

A database typically consists of more than one table. You need to repeat the process of
creating a table and adding records for each table in the database.

2
Using the Design and Update Features of Microsoft Access

Introduction

Once a database has been created and loaded with data, it must be maintained.
Maintaining the database means modifying the data to keep it up to date, such as adding
new records, changing the data for existing records, and deleting records. Updating can
include mass updates, or mass deletions; that is, updates to, or deletion of, many records
at the same time.

In addition to adding, changing, and deleting records, maintenance of a database


periodically can involve the need to restructure the database; that is, to change the
structure of the database. This can include adding new fields to a table, changing the
characteristics of existing fields, and removing existing fields.

Adding, Changing, and Deleting Record in a Table


Keeping the data in a database up to date requires several tasks: adding new records,
changing the data in existing records, and deleting existing records are a few of the tasks.

1. Adding Records in a Table

 You can simply reopen your table and add a new set of records

2. Changing Records in a Table


 You can simply reopen your table and make amendments

3. Deleting Records

When records are no longer needed, delete the records (remove them) from the table. To
delete a record, first locate it and then press the DELETE key. With the datasheet for the
table open, position the mouse pointer on the record selector of the record in which
the record is.

Changing the Structure of a Table

When you initially create a database, you define its structure; that is, you indicate the
names, types, and sizes of all the fields. In many cases, the structure you first defined will
not continue to be appropriate as you use the database. A variety of reasons exist why the
structure of a table might need to change.

3
To Change the Size of a Field

 Right-click the applicable table, and select Design View on the shortcut menu
and then point to the row selector for the field. Click the row selector for the
field. If your field has Text as Data Type, it will generally have a default size
of 50, the size should be changed to a more relevant field size e.g. first name,
may not be more than 15.

Creating Validation Rules

You now have created, loaded, queried, and updated a database. Nothing you have done
so far, however, ensures that users enter only valid data. To do so, you create validation
rules; that is, rules that the data entered by a user must follow. As you will see, Access
will prevent users from entering data that does not follow the rules. The steps also specify
validation text, which is the message that will be displayed if a user violates the
validation rule.

1. To Specify a Required Field

 Select the applicable table, and then position your mouse in the applicable field.
You can either use F6 to carry you to the Field Properties section->General, or
simply use your mouse to take you there.

 Click the Required text box and then click the down arrow that displays. Click
Yes in the list. The value in the Required text box changes to Yes. It is now
required that the user enters data into the field when adding a record.

2. To Specify a Range

 Select the field by clicking its row selector. Click the Validation Rule text
box in the Field Properties pane to produce an insertion point, and then type
the rule. Click the Validation Text box in the Field Properties pane to
produce an insertion point, and then type Must be between .. and .. as the text.
You must type all the text, including the dollar signs in this text box.

3. To Specify a Default Value

 Select the field by clicking its row selector. Click the Default Value text box
in the Field Properties pane and then type the value. The default value is
entered in the Default Value text box.

4
4. To Specify a Format

 To affect the way data is displayed in a field, you can use a format.
@ Text character (either a character or a space) is required
< Force all characters to lowercase
> Force all characters to uppercase.

Creating a Relationship between tables

The purpose of this option is for ensuring that in query actions duplicate values wont be
produced, and information from both tables can be accessed without much problems.
 Select the relationship icon
 Chose all the tables needed to be linked
 Identify the field name common to both tables, drag from the field name in
the first table to the field name in the second table.
 Ensure the enforce referential integrity option and then select create

Querying the Database


All your tools are organized as objects, tables, queries, forms etc. To manipulate any of
the objects select that item, and chose the applicable command.

Creating a Query

Select Queries from the Object button and then chose the create query in design view
option.

Using the Select Query Window

5
Once you have created a new Select Query window, you are ready to create the actual
query by making entries in the design grid in the lower pane of the window. You enter
the names of the fields you want included in the Field row in the grid. You can also enter
information in the Criteria row of the grid. When you so do, only the record or records
that match the criterion will be included in the answer.

Running a Query

Once you have created a query, you need to run the query to produce the results. To do
so, click the Run button. Access will then perform the steps necessary to obtain and
display the answer.

Using the Views

1. Point to the View button arrow on the Query Datasheet toolbar.

2. Click the View button arrow and then point to the view of choice.

Including All Fields in a Query

If you want to include all fields in a query, you could select each field individually. A
more simplified way exists to include all fields, however. By selecting the asterisk (*) in
the field list, you are indicating that all fields are to be included. Complete the following
steps to use the asterisk to include all fields.

Clearing the Design Grid

If you make mistakes as you are creating a query, you fix each one individually.
Alternatively, you may simply want to clear the query; that is, clear out the entries in the
design grid and start over.

1. Click Edit on the menu bar.

2. Click Clear Grid. Access clears the design grid so you can enter your next
query.

6
Entering Criteria

When you use queries, usually you are looking for those records that satisfy some
criterion.

Using Text Data in Criteria

1. To use text data in criteria, simply type the text in the Criteria row below the
corresponding field name.

Using Wildcards

Wildcards are symbols that represent any character or combination of characters. There
are two wildcards available in Microsoft Access. The first of the two, the asterisk (*),
represents any collection of characters. Thus Gr* represents the letters, Gr, followed by
any collection of characters. The other wildcard symbol is the question mark (?), which
represents any individual character. Thus t?m represents the letter, T, followed by any
single character followed by the letter, m, such as Tim or Tom.

Criteria for a Field Not in the Result

In some cases, you may have criteria for a particular field that should not appear in
the results of the query. Click the Show check box to remove the check mark.

Using Numeric Data in Criteria

To enter a number in a criterion, type the number without any dollar signs or commas.

Using Comparison Operators

Unless you specify otherwise, Access assumes that the criteria you enter involve
equality (exact matches). If you want something other than an exact match, you must
enter the appropriate comparison operator. (>, <,<=, >=)

Using Compound Criteria

Often you will have more than one criterion that the data for which you are searching
must satisfy. This type of criterion is called a compound criterion. Two types of
compound criteria exist, the AND criterion and the OR criterion. In the AND criterion,
each individual criterion must be true in order for the compound criterion to be true, and
both are entered. Conversely, an OR criterion is true provided either individual criterion
is true, in this case the alternate option is entered in the or section of that field.

7
Sorting Data in a Query
1. In some queries, the order in which the records are displayed really does not
matter. In other queries, however, the order can be very important. To order
the records in the answer to a query in a particular way, you sort the records.
The field or fields on which the records are sorted is called the sort key. If
you are sorting on more than field, the more important field is called the
major key and the less important field is called the minor key.
2. You can also sort on multiple keys.

Using an Update Query

(Need to Attend to Security Warning)


 Security warning->Options->Enable this Content

One approach to entering new information for a field would be to step through the entire
table, assigning each record its appropriate value. If most of the fields have the same
type, a simpler approach is available.

Initially, you can set all values to a particular value. To accomplish this quickly and
easily, you use a special type of query called an update query.

 Click Query in the list. The New Query dialog box displays. Design View is
selected.

 Click the OK button, and then be sure the Query1: Select Query window is
maximized. Resize the upper and lower panes of the window as well as the
field list box so all fields in the table field list display.
 Right-click the upper pane and point to Query Type on the shortcut menu.
 Click Update Query on the submenu, double-click the field in the table field
list to select the field, click the Update To text box in the first column of the
design grid, and then type the new value.

Using the Delete Query

You may need to delete records with specific criteria. A delete query can be used in this
case, as long as the records satisfy the particular criteria.

 Select the Query in design view.

 Click the OK button, and then be sure the Query1: Select Query window is
maximized. Resize the upper and lower panes of the window as well as the
field list box so all fields in the table field list display.

8
 Right-click the upper pane and point to Query Type on the shortcut menu.

 Click Delete Query on the submenu, you can then enter the criteria in the
specific field. You finally run the query.

Using Expression Builder

This allows you to build expressions and complete calculations on data within tables.

 Click the Builder to begin.


 Extract the Table needed, develop your formula, using the fields from the table
 Change the label to a more meaningful one.

You might also like