6database Management
6database Management
Mana
gemen
t 2
Ms D
B
r
0
o
w
n
e
2
1
E
This booklet contains notes related to The
Fundamentals of Hardware and
Software. The notes follow the CSEC
syllabus for the 2021 Information
Technology exam.
CSEC IT Class
June 2021 Sitting
1-869-661-2282
[email protected]
Upon completion of this section, students should develop expertise in the design of a
database management system in the development of computer applications.
Relational database – a database that contains more than one table with tables
sharing data among them.
Advantages
The information can be retrieved faster in ad hoc situations using queries
You can design and create your own queries with minimal knowledge of
your database
There are reduced updating errors and increased consistency as data is in
a standardized form
Data duplication
Data entry, storage and retrieval costs are reduced
Security of data is increased
You are able to present multiple views of data using report features
Disadvantages
They are more time-consuming to design than a manual database
Initial training is required
Suitable hardware and software are needed to run the program
They can be expensive to buy and maintain
2. Use terminology commonly associated with a database
Table – A collection of records, made of a set of rows and column. The
information you enter into the database will be stored in a table. In relational
databases, tables are also known as relations.
Tuple – The details about a particular entity are called a tuple. A tuple is
represented by a record in a database.
Row (tuple, record) – a collection of related fields. It contains a single row and
many columns. In relational databases, records are also known as tuples.
Primary key – Most database tables include a Primary Key field which stores a
unique value. The Primary Key is often a code number which identifies each
entity in the database. In a school, students might have a ‘student number’
which appears on a school card that they carry. The Primary Key is usually the
first field in the table.
Alternate key – Any are other field that is unique and can be used as a primary
key.
Candidate key – A field (or group of fields) that has the properties needed to be
a primary key. Only one candidate key will become the primary key. They
candidate keys that were not chosen are called secondary keys or alternate keys.
Composite key – a primary key or candidate key that contains two or more
fields
Foreign key – A field in a table that matches the primary key of another table.
Data type or field type
The data or field type determines the type of data that a field can store.
Data Type Purpose
Text Used to store alphanumeric characters (letters or numbers)
up to 255 characters.
Number Used to store numbers with or without decimal places.
Currency Used to store money values
Date/Time Used to store date/time type values
Autonumber Creates automatic numbers, such as an ID Number
Memo Used to store blocks of text like notes up to 65536
characters long
Yes/No Used for storing a yes or no value
3. Create a database
Before you create a table in your database, it would be wise if you plan what
you want it to contain. You need to think about the field names, field types and
field sizes. Such a plan is called the table structure.
Datasheet View
Datasheet View displays the table as a grid. The fields are displayed as columns,
and the records are displayed as rows. The field names are listed as the column
headers. Datasheet View displays the data. If this table had data, it would be
displayed in the cells. Each row represents a record. If the table had say, five
records, there would be five rows of data. If you want to find out a field's data
type, you need to select that field, then select the Fields tab on the Ribbon. The
field's data type and other properties will be listed on the right side of the
Ribbon.
Creating a table in design view allows you to create the table with your choice
of field names, descriptions and field sizes.
Design View
Design View doesn't display any data. Therefore, there's more space available to
display other settings. The fields are listed vertically. They are listed above and
below each other as opposed to side-by-side. You can see the data type listed
next to each field. When you click on a field (in the top frame), the bottom
frame displays the properties for that field. You can then change these
properties as required.
The first thing you have to do is to type in the field name in the next available
row. Although field names may be up to 64 characters, most are pretty short.
Having spaces in your field names is generally considered to be bad practice, so
instead of First Name, say FirstName.
Data type
When you first create a field, it is automatically set to type Text. If your field
isn’t going to be storing text, you should change this to the appropriate type of
data for your field. This is very important for two reasons:
i. This makes sure that the user isn’t allowed to enter the wrong type of
data. For instance, if you left an age field as type Text, nothing is
stopping the user from entering something like ‘ABC’ or ‘hello’ for the
age.
ii. The data type affects what you are able to do with the data. For
instance, if the type is Number or Currency you can perform calculations
with it.
Field size
If the data type is Text, this is the maximum number that can hold in the field.
Format
This controls the way the information is displayed in the Datasheet view
Decimal places
A data type is Number or Currency, choose the maximum number of decimal
places to be displayed or leave it as Auto if you want the computer to decide for
you.
Description
Each field can have a description other than the field name or the caption. The
description can be used to provide information about the field. It can be a
maximum of 255 characters and is displayed on the status bar of a form when
the field is selected.
Field properties
Each field has a number of properties, which are displayed when the field data
type is selected. The properties include the following:
Format – the format property can be used to create custom formats that
change the way numbers, dates, times, and text display and print.
Format properties do not change the way the data is stored, only how it
is displayed. To change the format of a field, different symbols are
entered in a Format text box. Text and Memo data types can use any of
four symbols, as shown in the table below.
Using a space between two quotation marks can create an empty space.
An example of the input mask for a telephone number is \(999”) “999\-
9999
Caption
The caption is the label for the field that is displayed on a form. If you
do not type in a caption, the default label will be the name of the field.
Enter the captions in initial caps and this has a tendency to present less
eye strain than all caps.
Default value
Default value is used to specify a value that is automatically entered in a
field when a new record is created. This property is commonly used
when most or all of the entries in a field will be the same. That default
value is then displayed automatically in the field. When a record is
added to the table, the user can either accept this value or enter another
value. This saves time when entering data. Character default values are
enclosed by quotation marks (“ “) and date default values sign (#).
Validation rule
When entering data, a check known as validation check can be
performed on the data to ensure that the data is valid. This check is only
performed if a validation rule was entered in the table structure. A
validity check is set by entering an expression containing the acceptable
values. Expressions can be made up of numeric, text or date data,
relational operators and/or logical operators. The data of the Number
data type must not be enclosed in quotation marks, whereas that of the
Text data type must be enclosed in quotation marks. The data of the
Date/Time field must be enclosed by # signs. When you add a
validation rule, you can also add validation text in the validation text
property.
Validation text
The error message that is displayed when the validation rule is broken.
You may create your own error message to notify the user of the
problem. Validation text appears in a message box if you attempt to
enter invalid information in a text field for which there is a validity
check. If you do not display a message, a default error message will be
displayed.
Required property
This property could be set to Yes or No. When it is set to Yes, it is
necessary for the user to input data in the field. This feature is very
useful for ensuring that data is entered in certain fields that are relevant
for processing the data. You will receive a message indicating that this
is a required field.
Indexed property
An indexed property will arrange records to facilitate fast searches of the
database. Selecting ‘Yes no duplicates’ prohibits duplicate records for
this field. Selecting ‘Yes – duplicates’ allows duplicates.
Inserting fields
Right-click on the box to the left on an existing field
Click on insert rows
Type the name of the new field
Deleting fields
Right-click on the row and click delete
Click yes when the confirmation box pops up
Establish relationships
Relationships allow you to join the tables to share records, thereby
preventing the duplication or repetition of data.
When you are about to set up a relationship between two tables, you can
follow the following rules:
Both tables must have at least one field containing common data
The fields containing common information must be of the same data
type
At least one of these fields must be a primary key
Linking tables
Select database tools, then click on relationships
Select the tables you want to link by clicking on them and clicking
the add button
Select the primary key and drag it to the foreign key of the second
table
Check the enforce referential integrity box (This will ensure that the
related tables correspond with each other, and it will not let you
create the relationship if they do not correspond.)
Select the create button to create the relationship
Now the relationship is set between the two tables and you can
retrieve information from both of them
Forms
Forms are similar to user interfaces, which allows database users to type data
into a database using specially designed templates, rather that straight into a
table. Using forms, we can format and display data, change or delete data and
create visual effects by adding colours, shades, lines and boxes to the fields.
Using the form wizard
Select the forms object in the database window then double click the
create form by using wizard
Select the table or queries you want from the drop-down list.
From this window, choose the layout of the form and select one of the
four layout options
Your form will be displayed with the first record of the table or query
being used for creating the form
Subforms
A subform is a form that is inserted in another form. The primary form is called
the main form, and the form that is enclosed in form is called the subform. A
form/subform combination is sometimes referred to as a hierarchical form, a
master/detail form, or a parent/child form.
Subforms are especially effective when you want to show data from tables or
queries that have a one-to-many relationship. A one-to-many relationship is an
association between two tables in which the primary key value of each record in
the primary table corresponds to the value in the matching field or fields of
many records in the related table. For example, you can create a form that
displays employee data, and contains a subform that displays each employee's
orders. The data in the Employees table is the "one" side of the relationship. The
data in the Orders table is the "many" side of the relationship — each employee
can have more than one order.
1. Shows the data from the “one” side of the relationship
2. Shows the data from the “many” side of the relationship.
Creating a subform
Select the form you wish to create the subform for
Right click on the form and open the design view
Make the design space larger so that you can add the subform at the
bottom
Select the subform option from the controls toolbar
Select the data source you wish to use for the subform
Add the required fields, then click next
Choose the linking field, then click next
Name the subform then click finish
Queries
One of the most powerful features of Database Management Systems is the
ability to perform queries: You can use queries to:
Display part of a table
Display records that meet a certain criterion
Perform calculations
Create/update tables
Delete records
Field settings
The following table explains what each field setting is for.
Row What it is for
Adding fields
If you double-click on a field in the top half of the Query Design window, it
will be added to your query. The fields that have been added to the query will
be shown in the bottom half of the Query Design Window
Remove fields
Select the field by clicking on the horizontal bar at the top of the field.
(Make sure that the whole mouse pointer changes to a black down
arrow.) The whole column should become highlighted.
Repositioning a field
Select the field by clicking on the horizontal grey bar at the top of the field
Hold down the left mouse button and drag the field to the new position
Release the left mouse button
Basic queries
Sorting
If you need a query’s results to be sorted by a certain field, use the sort row in
the query design to set the sort order for those fields. Access will sort by the left
most field that has a sort order, then by the next field with the sort order and so
on
Using * in criteria
The asterisk (*) has a special meaning when you put it in criteria. It acts as a
wildcard, which means ‘any group of characters or none at all’
Suppose you put the criteria sea*. This means the work sea followed by any
group of characters or none at all. So any of the following would meet the
criteria:
Seas
Seaweed
Sea
Sea shells by the sea shore
Criteria What is means Examples
Man* Anything that starts with MAN, MANURE,
the word ‘man’ Manchester United’
*man Anything that ends with Man, woman
the word ‘man’
*man* Anything that contains Man, manager,
the word ‘man’ woman, a man for
all seasons
Once your tables are joined, you add different tables to your query design and
proceed as usual.
Calculated fields
Select the option Query in Design View from the database window
Select the table Personal Details from the Show Table dialogue box and
choose add
Close
Select the fields required
In the empty column, type the name of the calculated field and its
formulae eg. Discount : [FeesRate] * .15. Please note that the equal sigh
(=) has been replaced with a colon (😊; the field name ‘FeesRate is
enclosed in square brackets and 15% is converted into its decimal form
as % is considered to be text.
Reports
Reports are used to present the information retrieved from the tables of a
database in a presentable manner so that it is useful and appealing to the user.
They can be created based on queries or tables. You can group, sort and have
summary features incorporated into a report.