Topic 1. Database management system MS ACCESS – data base
and its components. Creating tables – defining fields. Field
properties. Defining keys. Updating the table content.
Relationships between tables.
Basic exercise
1. Create a data base "Session" containg the following tables:
A table "Students" with a header :
StudNo
integer numbers between 1 and 15000 (validation rule is needed);
LastName
text of length no more then 30, display as capital letters,cannot be NULL;
ZipCode
text of five digits, three last digits are separated from the first two with hyphen
(-), the hyphen should be visible when a value is displed and entered (but the
hyphen should not be stored in the table), optional, may be zero length.
Primary key is StudNo.
A table "Courses" with a header :
Code
text of length 6: 2 letters from the range A-F and 4 digits separated from letters
by a hyphen;
Name
text of length no more 25 characters, display as capital letters, must be entered;
zero length is not allowed.
Primary key is Code.
Additional key is Name.
A table "Exams" with a header:
StudNo
see the description of the table Students;
CourseCode
see the description of the table Courses;
DateOfEx
display as short date, should be not later then today (validate), default date is
“today”
Grade
is a number from the set {2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5}; caption is Mark.
What should be a primary key of this table? Define the primary key ensuring, that each student can
have no more than one exam (grades) on the given course and additional key ensuring, that each
student can have no more than one exam (grades) at the given day (date).
3. Insert several rows into the tables Students and Courses also trying to violate validation rules, input
mask constraints and constraints following from the keys. Analyze effects of setting of Format, Input
mask, Validation rule/text, Default value and other reqired properties.
4. Define relationships between tables enforcing referential integrity, check cascade updating related
fields and deleting related records.
5. Open all three tables already created and tile their windows vertically or horizontally .
• insert a record into Exams for a student that does't exist in the table Students – what is a MS
Access behavour?
• insert a record into Exams for a course that does't exist in the table Courses – what is a MS
Access behavour?
• delete from Students a record of a student that has exams – what is a MS Access behavour?
• delete from Courses a record of a course that has exams – what is a MS Access behavour?,
• change the StudentNo of a chosen student having axams registered in the table Exams and
then check if the StudentNo value changes in the table Exams?
What is an effect of the enforcing referential integrity on the possibility to insert, delete and update
records in the given tables?
Additional exercises
1. Create a data base of a simple inventory control system for several storehouses storing materials in
a certain enterprise. Materials are characterized by: Id, name, price and unit of measurement. The
storehouses are characterized by Id and adaress. We would like to know what current material
stocks are. Assume that each material can be stored in many storehouses and each storehouse can
store many materials. Define relationships between tables enforcing referential integrity. Data
types and field properties at your discretion.
2. Create a data base concerning data about dishes composed of components. Each dish is
characterized by attributes: id and name. A component is characterized by: id, name and
vendorId. We would like to know what components are used in each dish and of what quantity
Define tables and relationships between them. Data types and field properties at your discretion.
Exercise tips and hints
1. Run MS ACCESS, choose „blank data base”, give the data base name: „Session”, point out the
folder, in wchich the data base is to be stored and press the button „Create”.
(in the version 2007/2010 you'll see a table „Table1” object in the datasheet view. Close the table
„Table1”. It disapears from the data base).
2. From the Menu choose the command „Create” and press button „Table design”. Appears the table
design window. The default name of the table created is „Table1”.
3. Define names, data types and properties of the table fields as follows.
Field name: type the name as stated in the exercise.
Data type: pull down the list the standard data types, choose the data type from the list
(default type is text).
Description: description of the field is optional (it does not affect other properties of the field
or the table).
Define other general field properties in the window at the bottom.
Field size: depends on the field data type – press F1 key for further information,
Format: is a character string that determines the way the field value is displayed on the screen
or printed – press F1 key for further information.
Input mask: character string divided by semicolons into three sections. Determines the
structure (template) of the field value that one can enter to the table. Values that does not fit to
the mask are not allowed. The input mask can constrain, for example, ZipCode to five digits
with hyphen separating the second and the third digit. The input mask character string in this
case could be, for example, 00-000;1;* or 99-999;1;* – press F1 key for further information.
Caption: is the synonymous field name occuring when the table is displayed or printed.
Default value: is a value that MS Access suggests to the user when new record is inserting
into the table. One can reject the suggestion and enter another, not default value. It can be an
expression which value is computed by the system.
For DateOfEx the default value could be the current date. To obtain this use the function
Date(), that returns the current date from the computer calendar.
Validation rule: is a boolean expression that constrains the value at the input. Values
satisfying validation rules can be entered to the tables. For StudNo it could be :
>0 and <=15000 or Between 1 and 15000.
For Code of the course you can use the operator Like „[A-F][A-F]####”.
For DateOfEx: use the function Date(). Press F1 key for further information
Validation text: The text that appears in the message box when the input value does not
satisfy the given validation rule.
Required: choose Yes when the field has to be always determined (NULL values are not
allowed for this field).
Allow zero length: choose 'no' when the field of text type is required (see above) and zero
length value is not allowed for it. For example the last name of the student, the name of the
course should be always required and zero length values are improper.
2
Indexed: property stated Yes enforce the system to build an additional data structure that
makes the search of records much quicker. Yes (No duplicates) allows to define the field as a
table additional key (record identifier).
Unicode compression: Microsoft Access uses the Unicode encoding standard. Each
character in this statndard is represented by two bytes. The text data consume more
storage space. In order to avoid this the compression can be applied.
6. After all fields of the table are defined the primary key has to be determined. To do this in the
table design view highlight field rows (one or more) that make up a key and press „Primary key”
button (if the field rows are not next to each other while highlighting rows hold the 'Ctrl' key).
Check key settings given in the Indexes window (press a button Indexes). If the key settings are
wrong remove them and try to define the key again.
To define a simple additional key in the table design view choose a field and set the field
property Indexed to Yes (No Duplicates).
In order to define a complex additional key open the Indexes window (a button Indexes) and add
the key definition similar to the definition of the primary key (Index name=Additional 1, names of
fields making up the key and set options as follows: Primary=No, Unique=Yes, Ignore Nulls=No.
7. In order to insert data values into the table change the design view to the datasheet view. You'll be
asked to name the table just created.
8. In order to define relationships (and foreign keys) between tables close all of them, choose
Database Tools tab and press a button called Relationships. In the Show Table window choose the
tables and add them to the Relationships window. Close the Show Table window. Choose two
tables that should be related. Drag the primary key field from the target table and drop it onto the
foreign key in the reference table. The Edit Relationship window opens and options Enforce
Referential Integrity, Cascade Update Related Fields and Cascade Delete Related Records are
available for check. If the primary key and corresponding foreign key are composed of a few fields
choose one field component of the primary key and drag it and drop onto the corresponding
component field of the foreign key. In the Edit Relationship window add remaing component
fields of the keys.
1
for exmple, instead of PrimaryKey
3
© Copyright 2026 Paperzz