In this series of practical tutorials you will build a simple prototype information system using the database management system, MS-ACCESS. The system is based on a lecturer's student record system.
Important:
Initially you will create the data files with the fields and their definitions
(ie. types, width, etc). Then you will create relationships between the tables.
This allows for more efficient usage and storage of the data in the database.
We then finally populate the tables with the data. Note: you are sometimes
restricted to entering certain data because of the relationships that are in
place.
Creating and Maintaining Database Files(Tables)
Note: When you wish to work on this database in future tutorials, you will select Open from the File menu, find your account in the network directory structure and select studrec from the Open window.
The first prototype system will consist of two tables (files) - a student table and a tutorial table.
From the database window ensure the Table tab is selected, then :
Enter the following
| Field Name | Data Type | Field Properties |
|---|---|---|
| stud_id | Text | Field size: 6 Input Mask: 999999 Required: Yes Allow Zero Length: No Indexed: Yes[No Duplicates] |
| stud_surname | Text | Field size: 15 Input Mask: >CCCCCCCCCCCCCCC Required: Yes Allow Zero Length: No Indexed: Yes[Duplicates OK] |
| stud_givenname | Text | Field size: 15 Input Mask: >CCCCCCCCCCCCCCC Required: Yes Allow Zero Length: No Indexed: No |
| tute_no | Number | Field size: Integer Required: Yes Indexed: Yes[Duplicates OK] |
The field, stud_id, will be specified as the key field (unique identifier) for this table. To do this select the stud_id row and click on the Primary Key icon (a small yellow key on the tool bar). The key icon will then be displayed in the stud_id row.
Save the table as student
Question
Use the help facility in MS-ACCESS (Press F1 or click on help)
to determine the meaning of the following special characters when used to
specify an Input Mask (you will need to highlight the Input Mask field before
hitting F1)
> C 9 0 < ?
From the database window again create a New table in Design View.
The following table summarises the characteristics of the tutorial table. Specify tute_no as the key field and save the table as tutorial.
| Field Name | Data Type | Field Properties |
|---|---|---|
| tute_no (Primary Key) |
Number | Field size: Integer Required: Yes Indexed: Yes[No Duplicates] |
| tute_time | Text | Field size: 12 Input Mask: >CCCCCCCCCCCC Required: No Allow Zero Length: Yes Indexed: No |
| tute_room | Text | Field size: 3 Input Mask: >?99 Required: No Allow Zero Length: Yes Indexed: No |
| tutor_no | Number | Field size: Integer Required: Yes Indexed: No |
To enable MS-ACCESS to maintain the integrity of the stored data, it is sensible to create a relationship between the two tables. This will be based on the common field, tute_no, present in both tables. The relationship will show that one tutorial can have many students and that the tute_no for a student in the student table must be present in the tutorial table.
Select Relationships from the Tools menu or use the appropriate button.
Add both the student table and the tutorial table and close the Show Table window.
Select tute_no in the Tutorial table and, while holding down the mouse button, drag the cursor to tute_no in the Student table - release the mouse button.
In the window that opens (the relationships window) select the following:
Now close the Relationships Window and save the Relationship Layout.
To add data to the tables, highlight the table name in the database window, select open and begin adding the data into the datasheet. Add the following data - due to the enforcement of referential integrity, you must add data to the tutorial table before the student table.
Question: why?
To find out why, try adding data to the Student table. What error message does Access display?
Enter the following test data into the tutorial Table:
| tute_no | tute_time | tute_room | tutor_no |
|---|---|---|---|
| 1 | MON 11:30 AM | E23 | 2 |
| 2 | TUE 9:30 AM | G17 | 1 |
| 3 | WED 7:30 PM | G23 | 1 |
Enter the following data into the student table:
| stud_id | stud_surname | stud_givenname | tute_no |
|---|---|---|---|
| 891012 | BROWN | STEPHEN | 1 |
| 900543 | ANDREWS | KRISTINE | 2 |
| 902514 | CARMON | VERA | 2 |
| 895601 | GRAHAM | JOHN | 2 |
| 904777 | BACON | CONNIE | 3 |
| 898265 | FRASER | ANGUS | 3 |
| 905123 | LORROWA | KEN | 1 |
| 885522 | STEPHENS | TRACEY | 1 |
| 890352 | NOLAN | MICHAEL | 1 |
| 901978 | GATESBY | DIANNE | 3 |
| 909533 | KENT | CLARK | 2 |
| 899003 | APPLEBY | ALMA | 3 |
| 901076 | HARRISON | GLORIA | 1 |
| 904372 | OWEN | SIMON | 2 |
| 905263 | VAUGHAN | CLAIRE | 3 |
To add a new record to a database table, select the table name in the database window and then select open. New records can be added at the bottom of the datasheet.
To modify an existing record, simply open the datasheet, and modify the appropriate record.
To delete a record, simply open the datasheet and select the appropriate record row by clicking in the leftmost column (ie. the grey column). The record should now be highlighted. To delete, press the delete key.
However remember that referential integrity may not allow deletions in the tutorial table if there are related records in the student table.
Attempt each of the following exercises.