0% found this document useful (0 votes)
15 views9 pages

Access Lab1

Answer

Uploaded by

myraggy.127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views9 pages

Access Lab1

Answer

Uploaded by

myraggy.127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CIT1163 – Database Management Access Lab#1

CIT1163 – DATABASE MANAGEMENT

LAB #1 – Microsoft Access

OBJECTIVES: CREATING A DATABASE AND TABLES


• create a database from scratch
• create a table using the Table window in Design View
• define field names and data types
• create a primary key field
• modify the design of an existing table
• define field properties for the different data types
• use a table in design view and data sheet view

CREATE A DATABASE FROM SCRATCH


1. Start Microsoft Access.
2. Create a new database called myDatabase.accdb. Note: make sure you save this file on
your USB flash drive or save it to your Drop Box so that you can use it in the future labs.
 On the File menu select New and select the Blank database template
 Enter myDatabase in the File name and point the save location to your flash drive
or Drop Box folder.
 Click on Create

CREATE A TABLE USING THE TABLE WINDOW IN DESIGN VIEW


3. Select the Create ribbon and click the Table Design button. Access displays a data
dictionary page where you can define each field in the table and its attributes.
 Access can automatically create a new table in a new database. Click on the View
button in the ribbon and select Design View. When prompted, save the table as
Contractors

DEFINE FIELD NAMES AND DATA TYPES


4. Create the data structure as follows:
(Hint: enter the Field Name, press Tab to move to the Data Type, press <Alt><↓> and
select type, press <F6> to cycle through the page parts down to Field Properties and enter
the size as necessary, press <F6> to cycle back to top pane, continue…)

Computer Information Technology Page 1 of 9


CIT1163 – Database Management Access Lab#1

Field Name Data Type Field Size*


Employee Number Auto number use the default assigned by the program
First Name Short Text 20
Middle Initial Short Text 1 Hint: When the cursor
Last Name Short Text 25 is in the datatype
Address 1 Short Text 30 column, type a “t” for
Address 2 Short Text 30
text, “a” for
City Short Text 25
autonumber, “d” for
Province Short Text 2
date, etc.
Postal Code Short Text 7

* Field Size is located on the General tab at the bottom of the data
structure window you are currently working in.

CREATE A PRIMARY KEY FIELD


5. Set the Employee Number to be the primary key.
• Click once on the cell where you typed “Employee Number”
• Click on the “primary key” icon on the toolbar (or Edit | Primary Key)
• A small key appears in the cell to the left of the words “Employee Number” which
identifies this attribute as being the primary attribute.

What is a primary key?

6. Choose Save from the File menu. If you haven’t already saved the table, in the Save As
dialog box, enter the name Contractors and click OK.

MODIFY THE DESIGN OF AN EXISTING TABLE


7. Click in the cell directly below the Postal Code cell. Add the following attributes.
Field Name Data Type Size Description
Job Category Short Text 1 Type P for Programmer, W for Writer,
or C for Clerical.
Hourly Pay Currency default
Date Available Date/Time Enter a date only if the Contractor
is not available when you call.
Emergencies Yes/No default
Notes Long Text
8. Save the table again (File | Save)
9. Click the Table window’s Close button (grey [X]).

Computer Information Technology Page 2 of 9


CIT1163 – Database Management Access Lab#1

DEFINE FIELD PROPERTIES FOR DIFFERENT DATA TYPES


10. Text, number, date/time, and currency fields can have a field Input Mask property that
specifies the format in which data is entered. (Do not confuse an input mask with an
output format.)
See the INPUT MASK CHARACTERS table at the end of this handout.
Determine an appropriate input mask for the column Postal Code (ensure upper case
letters).
• Ensure the tables or the All Access Objects option is selected.
• Double-click on the Contractors table name.
• Switch to Design view.
• Select the Postal Code field name.
• At the bottom of the window, under the General tab, click in the cell labeled Input
Mask.
• Enter the input mask in the cell. (Those are zeroes, not capital Os.)
• >L0L 0L0
• Save the table. Once you do, notice that Access put a \ in front of the space. That is ok.
• Also notice the lightning bolt beside the Input Mask. Click on it and select “Update…”
• Close the contractors table.

ENTER DATA INTO THE CONTRACTORS TABLE


11. Enter the following data (see next page) into the tables:
• Ensure the tables or All Access Objects option is selected
• Double click on the Contractors table name
• Click on the Open button and enter the data under the appropriate field headings

Computer Information Technology Page 3 of 9


CIT1163 – Database Management Access Lab#1

Employee Number: (1) Employee Number: (4)


First Name: Carla First Name: Samuel
Middle Initial: R Middle Initial: (none)
Last Name: Tannenbaum Last Name: Smaltz
Address 1: 1637 Fordham Address 1: 1701 Albemarle Rd.
Rd. Apt. D-14 Hint: TAB will move the
Address 2: Address 2: (none) cursor to the next field.
City: Toronto City: Hamilton Shift tab will move the
Province: ON Province: ON cursor to the previous
Postal Code: K1T 7J7 Postal Code: K2J 9I9 field.
Job Category: P Job Category: C
Hourly pay: 95 Hourly pay: 9
Date Available: Date Available: (none)
Emergencies: Check it (yes) Emergencies: (yes)
Notes: Low level database Notes: (none)
programming Employee Number: (5) Employee Number: (7)
Employee Number: (2) First Name: Jessica First Name: Sidney
First Name: Peter Middle Initial: (none) Middle Initial: (none)
Middle Initial: (none) Last Name: Smythe Last Name: Smithson
Last Name: Woodworth Address 1: WordSmiths Address 1: Computer Tools Works
Address 1: Star Address 2: 910 University Address 2: 7943-2301 Technology
Consultants Ave. Parkway
Address 2: 4152 Front St., City: Ottawa City: Kanata
#314 Province: ON Province: ON
City: Ottawa Postal Code: K8A 2Y1 Postal Code: K8B 7W1
Province: ON Job Category: W Job Category: P
Postal Code: K8A 9W9 Hourly pay: 50 Hourly pay: 150
Job Category: P Date Available: 9/1/13 Date Available: (none)
Hourly pay: 80 Emergencies: (No) Emergencies: (No)
Date Available: 7/1/13 Notes: Complete writing Notes: Provides customized
Emergencies: (No) manual service functions for financial calculations
Notes: Programs the user in C++, Fortran and COBOL
interface in C++
Employee Number: (3) Employee Number: (6)
First Name: Kevin First Name: Josephine
Middle Initial: M Middle Initial: B
Last Name: Smith Last Name: Estevs
Address 1: 42 Elm Circle Address 1: 47 Bleeker St.
Address 2: (none) Address 2:
City: Montreal City: Kanata Double-check your work and
Province: PQ Province: ON then close the Contractors table
Postal Code: Q3E 4B4 Postal Code: K8B 7W9 when you are done.
Job Category: W Job Category: P
Hourly pay: 55 Hourly pay: 90
Date Available: (none) Date Available: 12/15/13
Emergencies: yes Emergencies: Yes
Notes: Designed and wrote Notes: Programs the user
manual for our financial interface in C++ or Visual
analysis software Basic

Computer Information Technology Page 4 of 9


CIT1163 – Database Management Access Lab#1

QUERYING THE DATABASE

What is a query?

Notes:
• Queries are independent objects just like tables. You use queries to view, change, and
analyze data in different ways. You can also use them as a source of records for forms
and/or reports.
• A form or a report can be based on a table or on a query.
• A query displays a subset of all the fields and records in a table or multiple tables.
• The subset of data displayed by the query is called a dynaset (short for dynamic set).
Example: The following are instructions to create a sample query that displays names and
addresses of contractors who live in the Province of Ontario, sorted alphabetically by name.

Create a Select Query

1. Select the Create ribbon and click Query Design

2. Access opens the Show Table dialog box

a. Select the Contractors table in the Show Table dialog box

b. Click the Add button

c. A field list for the Contractors table is added to the Select Query window

d. Click the Close button in the Show Table dialog box.

3. Add Fields to the Query List

a. Double-click the title bar of the contractor’s field list to select all the fields. Drag
these selected fields (can drag all fields at one time once they are all selected) to the
first Field cell in the Design grid.

b. The fields listed in the Design grid at the bottom of the Select Query window are
those fields that will be displayed for this query. The order of the fields from left to
right in the grid will be the order the information will appear in the query.

4. If you do not want all of these fields to be displayed in the query, you can Delete
unnecessary columns.

a. Scroll right to the Notes field

b. Click once on the selector box above this column to select it. (The selector box is the
very narrow grey bar above the column name of Notes – the mouse cursor changes to
a down arrow when it hovers above the selector box).

Computer Information Technology Page 5 of 9


CIT1163 – Database Management Access Lab#1

c. Press Delete on your keyboard to delete it.

d. Using the same method, delete the Emergencies and the Employee Number
columns.

5. To delete more than one column at a time:

a. Click and drag over the selector boxes of the Job Category and Hourly Pay
columns

b. Both columns will be highlighted

c. Press Delete to delete both.

6. Sort the Data

a. To sort the data displayed by the query alphabetically by last name, you must
make Last name the first column of the query.

i. Click the selector box of the Last Name column and release the mouse
button.

ii. Now that the column is selected, click the selection box again, hold down the
mouse button, and drag left to make it the first column.

iii. Note: as you drag the Last Name column, a thick black bar appears to identify
where the column would be placed if you let go of your mouse button.

b. Two cells down from the Field name cell which has “Last Name” in it, there is a Sort
cell. Click once in this cell. Use its drop-down list box to select Ascending.

c. Likewise, select Ascending in the Sort cells for the “First Name” and “Middle
Initial” fields.

7. Limit the Records Displayed (Query Criteria)

a. We want to display all records for people who live in Ontario:

i. Scroll right so you can see the Province field

ii. In the Criteria cell for the Province field, type ON (ensure upper case).

iii. Click another field, so you can see that Access adds the quotation mark
delimiters around this (text) criterion.

8. Save the Query

a. Choose Save from the File menu. Access displays the Save As dialog box. As the
Query Name, enter Address List of Contractors from Ontario.

9. Run the Query.

Computer Information Technology Page 6 of 9


CIT1163 – Database Management Access Lab#1

a. Click the Run Query tool (! on toolbar), and after a moment, Access displays the
results of this query.

b. To automatically set all of the column widths, click on the Last Name label and drag
the mouse to the right to select all of the columns. Release the mouse button and
hover the mouse cursor over one of the column boundaries between the labels. The
cursor will turn into a vertical bar with two arrows. Double-click and the columns
will be auto-sized for you.

c. Close the Query window when you are done looking at it. (Say yes to the Save
dialogue.)

CRITERIA FOR LIMITING RECORDS DISPLAYED IN A QUERY


See the Arithmetic and Comparison Operators table at the end of this handout.

Wildcards are available to add flexibility to the query criteria.

Wildcards that are available in Access are:


* – stands for any number of characters; any characters
? – stands for one character; any character

Computer Information Technology Page 7 of 9


CIT1163 – Database Management Access Lab#1

BUILD THE FOLLOWING QUERIES


A. Display all fields for all the contractors who are available by July 1, 2013. Auto-set the
column widths. Save this query as Contractors available by July 1, 2013.*
Hint: Try <=#7/1/2013# and you should find one and only one.
B. Display all fields for all the contractors who do not live in the Province of Ontario. Auto-set
the column widths. Save this query as Contractors who do not live in Ontario.
Hint: Try <>”ON” and you should find one and only one.
C. Display all fields for all the contractors who do live in the Province of Quebec. Auto-set the
column widths. Save this query as Contractors who live in Quebec.
Hint: there is only one.
D. Display all fields for all the contractors who will become available in the fourth quarter of
2013. Save this query as Contractors available in the fourth quarter of 2013.
Hint: Try Between #10/1/13# And #12/31/13# and you should find only one.
E. Display all the fields for all of the records where the person’s last name begins with an S.
Save this query as Contractors with last name starting with an S.
Hint: Try “S*”(the * is a wild card for any number of characters). There are four.
F. List the Last Name, First Name, and Hourly Pay of the employees who make more than
$50.00 per hour, sort the information in Descending order by Hourly Pay. (To include
specific fields, click on the field in the field list and drag it to the field cell in the design
grid). Save this query as Contractors who make more than 50 per hour.
Hint: There are five.
G. List the Last Name, First Name, and Notes for all employees who could be used in an
emergency. (To include a field in the query, but not display it in the results, you must
uncheck the “Show” box for that field). Save this query as Contractors who can be used
in an emergency.
Hint: There are four.

* Date tip: If you find that the date is not the same as in this lab exercise, then you may wish
to set the Windows OS preferences. Do this: Start → Control Panel → Regional and
Language Options → Press the Customize button → Select the Date tab → set your
preferences here.

Computer Information Technology Page 8 of 9


CIT1163 – Database Management Access Lab#1

INPUT MASK CHARACTERS


Text, number, date/time, and currency fields can have a field Input Mask property that specifies
the format in which data is entered. (Do not confuse an input mask with an output format.)
Character Meaning
0 Number required
9 Number or space can be entered but is not required
# Number, plus or minus sign, or space can be entered but not required
L Letter required
? Letter can be entered but not required
A Letter or number required
a Letter or number can be entered but not required
& Any character or a space required
C Any character or a space can be entered but not required
< Characters that follow converted to lowercase
> Characters that follow converted to uppercase
! Characters fill from right to left rather than from left to right. Can be used
when characters on the left are optional, and can be included anywhere in
the mask
\ Following character is displayed literally rather than read as a code

COMPARISON OPERATORS
Operator Meaning
= Is equal to
> Is greater than
>= Is greater than or equal
to
< Is less than
<= Is less than or equal to
<> Is not equal to

LOGICAL OPERATORS
Operator Meaning
AND Both criteria must be true to match
OR Either criterion must be true to match
XOR One of the criteria but not both must be true to
match
NOT The criterion must be untrue to match
Between ... And Finds a range of values

Computer Information Technology Page 9 of 9

You might also like