1 Operate Database Application
1 Operate Database Application
LEVEL II
LEARNING GUIDE
This learning guide is developed to provide you the necessary information regarding the following
content coverage and topics –
• Opening and designing DB application and principles
• Creating DB objects
This guide will also assist you to attain the learning outcome stated in the cover page. Specifically, upon
completion of this Learning Guide, you will be able to –
• Open and design database application incorporating basic designprinciples
• Create database object according to database usage, as well as user requirements
• Modify database object as required
• Add and modify data in a table according to information requirements
• Add, modify and delete records as required
• Save and compile database objects
Learning Activities
Information
- data processed to increase knowledge in the person using the data
Database
- organized collection of logically related data
Naming conventions
case-sensitivity.
• Separate name parts by underlines, never by spaces. This way, you improve the readability of each name
(e.g.
product name instead of productname). You will not have to use parentheses or quotes to enclose names
using spaces as well. The use of spaces in a database name is allowed only on some systems, while the
underline is an alphanumeric character, allowed on any platform. Thus, your database will become
platform independent.
• Do not use numbers in the names (e.g. product_attribute1). This is proof of poor design, indicating a
badly divided table structure. If you need a many-to-many relation, the best way to achieve it is by using a
separate linking table. See how here. Moreover, using numbers to differentiate between two columns that
store similar information might be an indication that you need an extra table, storing that information. For
instance, having a location1 column in a manufacturers table and a location2 column in a distributors
table could be solved by creating a separate table that stores all locations, and that is referenced by both
the manufacturers and distributors tables via foreign keys.
• Do not use the dot (.) as a separator in names. This way you will avoid problems when trying to perform
queries, as the dot is used to identify a field in a specific column.
In SQL language, manufacturer_man.address_man means the address column from the table that stores
information about manufacturers.
• Do not use any of the reserved words as names of database elements. Each database language uses some
words as names for internal functions, or as part of the SQL syntax.
For instance, using order as the name of a table that stores product orders from an online shop is bad
practice, because order is also used in SQL language to sort records (ascending or descending).
• When naming the elements, do not use long or awkward names. Keep them as simple as you can, while
maintaining a clear meaning. It's also a good idea to use names which are close to the natural language.
Example, description_3rd is certainly a better name for a column that stores product descriptions than
dscr_pr or some generic name as field_1.
Database names
Each database must have a name of its own, which should also follow some conventions:
• Use the project name as the name of the database.
• Prefix the database name with the owner name, separated by an underscore. The owner might be a person
(e.g. the project manager) or the application for which the database is created.
For example, acme_catalog can be a good name for the database storingthe product catalog of the ACME
company.
Table names
Tables are some of the most common elements used in an application, as they store the columns, and as such are
mentioned in each query. Therefore, the following conventions should apply to tables:
• Table names contain the name of the entity that is being defined, followed by a three letter acronym of
that name (e.g.
category_ctg). Optionally, you can use the same prefix for all tables in the same database.
For example, acme_product_prd, acme_manufacturer_prd, acme_category_prd can be tables from the
acme_catalog database.
• Prefix tables that define the same larger entity with a 2 or 3-letter acronym that identifies it.
For example, e.g. hr_applicant_app, hr_job_job and hr_resume_rsmareall tables that belong to the
Human Resources Department of a large corporation database.
• Do not use generic prefixes, such as tbl_, or db_, as they are redundant and useless.
• Use short, unambiguous names for each table, restricted to one word, if possible. This way tables can be
distinguished easily.
• Use singular for table names. This way, you avoid errors due to the pluralization of English nouns in the
process of database development. For instance, activity becomes activities, box becomes boxes, person
becomes people or persons, while data remains data.
• Use clear names. Do not overdo it using abbreviations and acronyms. While using a shorter name might
help the developers, it makes the meaning less clear to other members of the team. Using clear names
makes the design selfexplanatory.
• Prefix lookup tables with the name of the table they relate to. This helps group related tables together (e.g.
product_type, product_status), and also helps prevent name conflicts between generic lookup tables for
different entities. You can have more than one generic lookup table for an existing master table, but
which address different properties of the elements in the table.
Column names
Columns are attributes of an entity, describing its properties. Therefore, the name they carry should be natural,
and as meaningful as possible. The following conventions are recommended:
• All keys are used for indexing and identifying records. Therefore, it's a good practice to put the id particle
in their name.
This way, you'll know the field is used as a key.
• The primary key is used to uniquely identify each record. That is why its name should be made up of the
id particle, followed by the table name acronym.
For instance, for the table product_prd, the primary key is id_prd.
• The foreign key name should be composed by the id particle, followed by the acronym of the referred
table, and then by the acronym of the table it belongs to.
For example, the idctg_prd foreign key belongs to the products table (product_prd), but it refers to the
categories table (category_ctg). This way, the table being referenced is obvious from the key name.
• Each column name should be followed by the 3-letter table acronym. This way, each column has a unique
name across the database. Without the table acronym, you would end up having two columns called
"name", one storing the product name and the other the manufacturer name. Instead, name_prd and
name_man can easily be distinguished.
• Date columns should use the “date_” prefix, and the Boolean type columns should use the “is_” prefix.
For instance, date_birth stores the birth date of a person, while is_confirmed could indicate the order
Creating DB objects
status for a product in a shop, using true/false values (or 0/1).
A table is a database object that you use to store data about a particular subject, such as employees or products.
A table consists of records and fields.
Each record contains data about one instance of the table subject, such as a particular employee. A record is also
commonly called a row or an instance.
Each field contains data about one aspect of the table subject, such as first name or e-mail address. A field is also
commonly called a column or an attribute.
A record consists of field values, such as Contoso, Ltd. or someone@example.com. A field value is also
commonly called a fact.
TABLES
QUERIES
A record
A field
A field value
A database can contain many tables, each storing information about a different subject. Each table can contain
many fields of
different types of data, such as text, numbers, dates, and hyperlinks.
A query is a way of asking questions about the data in the tables according to certain criteria.
FORMS
Forms are used mainly to display the records in the table in a user-friendly way.
REPORTS
Reports are used to print information from the database. They provide professional – looking output from
the table or query.
MACROS
A macro is a set of one or more actions that perform a particular operation. Macros can be created to add
buttons to print a report, open a form and other commonly used tasks.
Text This is the default setting. Used for shorter text entries. Can be combination of
text, numbers, spaces and symbols. Maximum length 255 characters but you
can set it to less using the Field Size property.
Memo Used for longer text entries. Maximum length 65,535 characters
Date/Time This stores a date or a time or a date and a time. There are several formats for a
date/time field.
Currency Monetary values. Normally in the UK this will be set to pounds and work to 2
decimal places
AutoNumber An AutoNumber field will number records automatically as you enter more
data. The field acts as a counter. Duplicates are avoided and so AutoNumber
fields are ideal as the key field.
An AutoNumber cannot be edited and when an AutoNumber record is deleted
Access does not allow you to go back and reuse this number.
Yes/No Only allows logical values such as Yes/No. True/False
OLE Object An object linked to or embedded in MS Access table. This might be an image
or a sound or a file created in another package such as MS Excel or MS Word
Hyperlink A hyperlink address. This can be linked to:
An object in you Access file e.g, another table
Another logically stored file
A Web page
An email address
Lookup Wizard This data type creates a lookup table so that you can choose a value from drop-
down box.
Field Properties
Property Description
Field Size This is used to fix the maximum length of a text field. The default is 50
characters. The maximum length is 255.
Format This fixes how data can be displayed, for example dates can be displayed
in many different forms such as 26/01/2012 or 26 Jan 2012 or 26 January
2012
Input Mask This sets a pattern for the data to be entered into this field.
Caption This is the field label in a form or report. You are likely to need to use
this property.
Default Value This is the value entered into the field when the record is created. It is
usually left blank but can be very powerful.
Indexed This allows data to be stored in the order of this field which speeds up
searches.
Allow Zero Length This is used with text fields to decide whether records in that field are
allowed to contain zero length or empty text strings
Unicode Compression This is a method of compressing the data entered in this field.
A postcode consists of one or two letters, then one or two numbers, then a space, a number and two
letters. All the letters must be capital letters. Examples are B11BB or DE13 0LL The input mask would
be >L?09 0LL
A driving license number in the form BESWO150282 MB9BM could have >LLLLL#000000#LL0LL
as an input mask.
Product Codes of the format A2C-123-456. A possible input mask might be AAA-000-0000.
Input masks are very powerful and need a lot of thought. It is possible to use the Input Mask Wizard to set
up an input mask for a field. At this stage you may wish to ignore input masks unless you know the exact
format of the input data.
You can also use expressions in the field property. Typically = Date() will return t current date from your
PC.
In a Library Book Loaning system, the default value for the Date of Loan field could be set to =Date()
and similarly for the Date of Return, the default value could be set to = Date() + 14 (assuming a 14 day
loan period).
I. Matching Type. Write the letter of the term in found in column B that matches the description in
column A. Write your answer in the space provided b to the terms in column B. Write the letter of
before each item. (10 points)
COLLUMN A COLUMN B
_______1. A value that is added automatically when a new record is added in the a.
Input masks database.
_______2. An input masks character which means that any character or space may
be b. LIKE entered.
_______3. Collection of related data. c. Field
_______4. Defines what sort of data to expect in a field. d. Information
_______5. It is also commonly called a column or attribute. e. Report
_______6. It is the error message if the data entered is invalid. f. Validation text
_______7. It provides a professional – looking output from the table or query. g. Database
_______8. Tests a text or memo field to match pattern string of characters. h. IN
_______9. Tests for ‘equal to’ any item in a list. i. C
j.
AND
_______10. Used to display on screen a pattern for the data to be entered into a field.
k. Data type
l. Default Value
2. What are the three things to consider in establishing a naming convention? (3 points)
Answer Key:
I. Matching Type
1. L
2. I
3. G
4. K
5. C
6. F
7. E
8. B
9. H
10. A
II.
1. Tables
2. Queries
3. Forms
4. Reports
5. Macros
8. It provides a clear structure, each component using the standard naming rules.
9. The database logic can be understood by anyone knowing the naming convention.
10. Maintenance work is reduced, as future developers will not have to waste time figuring out what each
field is.
Operation Sheet 1 Setting Up and Entering the Data in the Student Table
3. Use the Save in drop-down box to locate where you want to save your database. Name the file
ITSMSchool and click Create.
The Database Window loads, this is the control centre from which you can design tables, queries, forms, reports
and macros.
6. YourTable Design window should appear as in the figure below. Save the table by closing the window
or by choosing File, Save. The Save As dialogue box will appear, name the table Student.
During the course if setting up the table it is probable you will make mistake or decide to make a change to
your table’s structure.
Inserting a Field
Click on the row selector of the field below the insertion point.
Press the Insert key on the keyboard or click the Insert Row icon on the toolbar.
Deleting a Field
Click on the row selector of the field to delete.
Press the Delete key on the keyboard or click the Delete Rows icon on the toolbar.
Moving a Field
TITLE
The Title field can only have the values Mr, Mrs, Miss and Ms. We can use the Lookup Wizard
whenever we want to restrict the data entered into a field to certain values.
1. Click on the Title field name.
2. In the Data Type column click on Lookup Wizard.
1. Select the Field Name: Surname and set the Field Size to 20, repeat for Firstname.
2. Select the Field Name: Address1 and set the Field Size to 30, repeat for Address2.
TELNO
Select the Field Name: TelNo and set the Field Size to 15.
DATEOFBIRTH
The student table uses three Date/Time fields. We will use the Short Date format for each.
1. Select the DateOfBirth field.
2. Click on the Format box in the Field Properties.
3. A drop-down list appears. Choose Short Date
It is also possible to use the Input Mask wizard to set a placeholder _ _ / _ _ / _ _ _ _ for each date
entered.
• Data entered into the Gender field is validated and any invalid entries rejected.
• Placeholders appear in the fields where you have to set input masks to make data entry easier.
• Enter data into Yes/No fields by ticking the check box for Yes and leaving unchecked for No
When you finished entering the data, close the table by clicking on the Close icon. You will return to the
Database Window with the name of the table highlighted.
Save the table as Product and switch to Datasheet View mode to enter:
ProductCode Size CostPerDay Status PictureofProduct Description
Product
Type
BB01 Bouncy 15 80.00 Available For Rent
Boxing
Save the table as Subject and switch to Datasheet View mode to enter:
SubjectCode DescTitle StartTime EndTime Day Room
IT001 Communications 1 07:30 12:00 Monday J41
CR002 Basic Construction 13:30 17:00 Tuesday A12
EE016 Digital Design 8:00 12:00 Friday B14
Introductory 150
Standard 400
Test 300
3. Check the Enforce Referential Integrity box but DO NOT check the Cascade Delete Records box.
Click on Create.
** A link called the Relationship Line is set up between the two tables.
4. Click on the StudentID field in the Student table and drag it on top of the of the StudentID field in the
Lesson.
5. Check the Enforce Referential Integrity box and click on Create.
6. Repeat the process for the LessonType field, dragging it from LessonType table to Lesson and check
Enforce Referential Integrity.
Note: The number 1 and the infinity symbol (∞) mean that all three relationships are one-to-many. A
StudentID appear only one time in the Student table as it is a unique ID. However, a StudentID can
appear many times in the Lesson table as the student needs many lessons.
Similarly, the InstructorID can only appear once in the Instructortable but many times in the Lesson.
The LessonType can appear only once in LessonType table but many times in Lesson table.
7. Save the layout by clicking File, Save from the menu.
REFERENTIAL INTEGRITY
Referential integrity is a system of rules that MS Access uses to ensure that relationships between records
in related tables are valid and that you don’t accidentally delete or change related data.
DELETING RELATIONSHIPS
If you wish to delete a relationhip:
1. Open the Relationship window as before.
2. Click in the RelationshipLine of the relationship you wish to delete and press delete key. Alternately,
you can right click on it and choose delete.
RELATIONSHIPS
Keeping data separated in related tables produces the following benefits:
• ConsistencyBecause each item of data is recorded only once, in one table, there is less opportunity for
ambiguity or inconsistency.
For example, you store a customer's name only once, in a table about customers, rather than storing it
repeatedly (and potentially inconsistently) in a table that contains order data.
• Efficiency Recording data in only one place means you use less disk space. Moreover, smaller tables
tend to provide data more quickly than larger tables. Finally, if you don't use separate tables for
separate subjects, you will introduce null values (the absence of data) and redundancy into your tables,
both of which can waste space and impede performance.
• Comprehensibility The design of a database is easier to understand if the subjects are properly
separated into tables.
FORMS
A form is a type of a database object that is primarily used to enter or display data in a database. Most forms
are bound to one or more tables and queries in the database. A form's record source refers to the fields in
the underlying tables and queries.
QUERIES
A query is a derived item in the database meant to answer specific questions that relate to the information
in the database. It is the means to retrieve relevant information in one or more tables. Queries are handy
during data processing.
REPORTS
Reports provide a means of organizing and summarizing data. Reports are often used to present an
overview highlighting main points and trends. A report can be a simple list, a status report or a monthly
production report.
MACROS
Macros in Access can be thought of as a simplified programming language which you can use to add
functionality to your database. For example, you can attach a macro to a command button on a form so
that the macro runs whenever the button is clicked. Macros contain actions that perform tasks, such as
Modules, like macros, are objects you can use to add functionality to your database. Whereas you create
macros in Access by choosing from a list of macro actions, you write modules in the Visual Basic for
Applications (VBA) programming language. A module is a collection of declarations, statements, and
procedures that are stored together as a unit. A module can be either a class module or a standard module.
Class modules are attached to forms or reports, and usually contain procedures that are specific to the form
or report they're attached to. Standard modules contain general procedures that aren't associated with any
other object. Standard modules are listed under Modules in the Navigation Pane, whereas class modules are
not.
Now that you know how to put together a program, you are ready to give it a try. To create a VBA
procedure, you follow many of the same steps you follow when you created macros. The general steps in
VBA programming are as follows:
1. Identify the task you want to accomplish.
2. Plan the steps needed to accomplish that task.
3. Create the programming code necessary to implement the steps.
4. Test the program.
5. Refine the program.
Notice that there are several different parts to the VBA Editor. In the upper left corner is what the
editor refers to as the Project window. This is where you can see the different elements of your project
and any modules that have been defined in the workbook. Just below the Project window is the
Properties window. Here you can specify different attributes of whatever you have selected in the
Project window. For most simple development needs, you will never do much with the Properties
window. To the right of the Properties window, and at the very bottom of the screen, is the immediate
window. This is where you can either test parts of your procedures during development or you can
find the immediate results of various commands. The Immediate window comes in very handy during
testing and debugging, when they are necessary.
The Procedure box is where you indicate the name of the procedure on which you want to work. If
you choose or specify a different procedure in this box, the information Access shows in the Module
window changes to reflect the VBA statements you have assigned to that procedure.
The top level of a module is the Declarations section; It begins with the procedure name you indicate
in the Procedure box when you first create a module. Take a look at the Module window (Figure 20-
1). It contains the programming code already defined for the declarations section. In this instance,
there is only one line of code defined--a statement that indicates the database's default sort order.
To enter programming statements into a procedure, you type them in the Module window. As you
enter information, Access checks to make sure it can understand what you type. In other words,
Access checks the syntax of what you enter. You use the correct syntax when you follow the VBA
rules of grammar.
You can cut, copy, and paste sections of code using standard Windows mouse or keyboard techniques.
You can perform these operations either in the same procedure or between different procedures.
4. Click the double arrow (>>) to put all available fields across to the
selected fields and click on Next.
6. Place Student as title of the form. Select Open the form to view or enter information. Click Finish to
save your form.
FORM VIEW
Form View allows to view and edit records one at a time. Enter Form View form the Database Window by
selecting the form and clicking on Open.
DATASHEET VIEW
Datasheet View allows you to view and edit the records all on one screen. The form LessonType is shown in
Datasheet View.
DESIGN VIEW
Design View allows you to edit the form. Enter the Design View from the Database Window by selecting
form and clicking on Design.
• To select more than one control, simply drag out a rectangle across the controls you wish to select or
Select the first control and hold down SHIFT while selecting further controls. Resizing
Controls
• Click on the control to select it and then drag the resizing handles in or out to resize it.
Adding a Control
• If you want to add a control for a field, click Add Existing Fields. The Field List will appear on the
screen and you can highlight the field and drag and drop it to the required position.
QUERY 1
1. Load the ITSMSchool database.
2. In the menu, click Create and select Query Design.
3. In the Show Table window select Lesson, click on Add and then Close.
4. Double click on LessonNo in the table Lesson field list. Then double click on each of the next fields in
turn: StudentID, InstructorID, Date, StartTime, LengthOfLesson. The fieldnames will appear in the
grid as shown below:
QUERY 2 Finding the contact details for students who have not passed the theory test.
1. In the menu, click Create and select Query Design.
2. In the Show Table window select Student, click on Add and then Close.
3. Select StudentID in Student table and drag it to the field cell.
4. Drag and drop the fields Surname, Firstname, TelNo and PassedTheoryTest in the same way. The
fieldnames will appear in the grid as below.
5. Now select the criteria by entering No in the criteria row the PassedTheroryTest column. Searching
Yes/No fields is justYes or No in the criteria cell.
6. To run your query click on Datasheet View icon.
5. Run the query to view the records and save the query as BetweenDates.
In this unit, you will learn how to set-up reports to output information from the database.
REPORT 1: Setting up report to of set-up instructor contact details.
We want to set-up a report to show a list of all instructors and their contact details. This report will be based on
the Instructor table.
1. At the Database Window select Create and click Report Wizard.
2. In the Tables/Queries tab, choose Instructor.
3. Select all fields of the Instructor table and click Next.
4. In the grouping level dialog box, click Next.
5. Choose Surname and ascending order for the sort dialog box. Click Next.
6. Click on Tabular and click Next.
DESIGN VIEW
The Design View window allows you to customize your report to suit your requirements. Reports are
edited in the same way as editing forms. As with forms it is possible to:
• Add, edit and remove fields
• Add text and titles
The top part of the report is the Report Header. Controls in the Report Header appear only once at the
beginning of the report. It is suitable for titles.
The second part of the reports is the Page Header. Controls in the Page Header appear at the top of every
page. It is suitable for column headings.
The third part of the report is the Detail. This is used for the data in the report.
The fourth part of the report is the Page Footer. Controls in the Page Footer appear at the bottom of
every page. It is here the wizard has inserted the page number and date.
The final part of the report is the Report Footer. Controls in the Report Footer appear only once at the
end of the report.
3. Select the Title section in the Detail section and holding the SHIFT key down select the Title control in the
Page Header section.
4. Drag the resizing handles in to make one of the controls smaller. The other control will also be resized.
5. Select all the other controls to the right of Title in the Page Header and the Detail sections. (Click on one,
then hold down the SHIFT key and click on each of the controls in turn.) With care you may find it easier
to drag out a rectangle across the controls.
6. Using the ‘open hand’, slide all these controls to the left.
7. Insert spaces in the Header controls for InstructorID,Surname, Firstname, address, etc. Select the control
for the Mobile No control.
8. Click on View, Layout Preview mode. You may also haveto align some of the data controls in the Detail
section.
Department
004 Arts and Sciences Don Bosco 844 – 1872 loc 202
Department
Section