Databases
Databases
We are often faced with the need to keep, search for or give a report of daily experiences. In order to
cater for these problems, people use diaries or files to store data. Human beings also use manual
devices to store and manage data.
However, these methods have a number of weaknesses;
i. Unnecessary data duplication
ii. Tiresome and boredom when searching for an item
iii. Misleading reports due to poor data entry and organization.
iv. Poor update of records.
Today, computerized systems have changed the way data and information is managed by use of
special programs called DATABASE MANAGEMENT SYSTEMS (DBMS)
DATABASE CONCERPS
Computerized database creation and manipulation is achieved using database management system.
Database software- A program that allows one to create, manage and manipulate a computerized
database.
Software
This software facilitates the creation, organization and maintenance of databases.
i. Flat files
In this model, a database holds only one set of data. It is not different from the manual file. Example.
A class teacher’s file may have the performance cards for students:
Name PETER
Adm No 2657
No. of subjects 7
Average 70
Position 3
ii. Hierarchical model:
In his model, data items are arranged in a hierarchical (tree) form. I.e. The main item forming the
root component. Before you access items on a lower level, you must pass the higher level.
Example:
To keep the records of a certain student (Peter) the administration uses Peter as the root of all other
records about him.
PETER
Item 2
Item 1 Item 4
Item 3
Example
NB:
Table 2, is related to table 1 through customer ID
Next generation of data base model will look at record as object that are independent and relate
with other object in the database.
Most database software provide the user with collection of feature that helps the user to
manipulate data in a database . This feature includes:
1. Table/files
2. Queries
3. Report generation
4. Form interface
5. Programming languages
Ms Access has got all above features and two additional feature which are nt common in other
database. They are:
Macros
Modules
a) Tables/file structure
A table is a data structure used to hold records. A table is made up of rows and columns
Each row holds a record where else column hold similar record fields
Example:
b) Queries and Query language
This is a database tool used to search for (or question a database) on specific records. It must
there4 return answer. In Ms access, the answer from query is called dynaset
Query statement are written using special language called structured query language(SQL)
Example:
If you are the manager in WINNERS company which runs an automated production system,
you may wish to the number of employees who earn a salary less than 30000. You are ther4
require to type the query for the same.
A form is a graphical interface that resembles the ordinary paper forms used to collect data.
However, unlike the ordinary data collection paper, the database form enables the user to view
and enter data into a table.
d) Reports.
Most databases allow the user to generate a report using a table or query.
The report generator also allows the users to specify the report layout and the data item to be
output.
Example:
FIELD PROPERTIES:
As you develop complex tables, there will be need to specify finer details related to fields.However
the field properties depends on the data type of the field selected.
Various field properties are:
a. Field size:
Allowing the user to specify the number of characters instead of the default.
E.g. can set the field size for Id number to be characters.
b. Format:
Determines how information appears on the screen once printed e.g. one can format a number to
scientific, currency, percentages etc.
c. Decimal places:
Used to specify the number of decimal places
d. Input mask:
Used to automatically format a field entry into a specified format.
Example: If you enter a number 0724203644 and the input mask format is 0000-000-000,The
number will automatically be changed to 0724-203-644
This format is mostly used for Addresses, Phone numbers etc.
e. Caption:
It’s a more descriptive name for a field e.g. studname could be student name.
f. Default value:
A number that will automatically appear in a datasheet or form if nothing is entered. Example: Date()
: Automatically displays the current date.
g. Validation rule:
These are logical rules which restrict values to be entered in a field.
Example: >=0 and <=100 Restricts the values to be entered in a field to 0 and 100.
h. Validation text:
A message displayed once a validation rule is violated.
Example:
“You have entered a value outside the expected range”
i. Required:
Determines whether a field has to be entered in the field before you proceed to the next field.
j. Allow zero length:
Allows the user to proceed without making any entry into the field.
k. Indexed:
An index facilitates the organisation of records for easy search.
Example:
A primary key, an index sets no duplicates to control double entry of records (Redundancy).
PRIMARY KEYS AND INDEXES:
An index is a database feature that is used to speed up search and sort operation.
A key field also called primary key is a special index that enforces uniqueness in a table so that a record is
not entered twice.
Ms Access uses a primary key to search for data in a data and also establish relationship between tables.
Once a primary key has been set, if is used to index or sort the datasheet.
Practical work
i. Data on identifying related tables
ii. Create primary key
iii. Create an index key
ENTERING DATA INTO A TABLE.
i. Open the database with the required table.
ii. Click the “Tables” tab and double click the table you want.
iii. Enter the data into the fields use the tad key to go to the next field.
Once you go to the next row the above data is saved automatically.
EDITING A DATABASE.
a) Modifying the datasheet view:
i. To adjust column size.
ii. Point at the column border and drag it to the required size
Or
To recorder fields;
Select the column to the top
Type the desired height.
NB:
You can also use Wildcards to search if you are not sure of what you are searching
Example: J* Searches all names starting with J.
b) Using Queries
Queries are the fastest way to search for information in a table. They are also used to perform
calculations on fields from one or multiple tables.
There are 2 types of Queries:
[a.] Action Query
[b.] Select Query
I. Select Query
This is the mostly used type of Query. It lets the user to specify the search criteria and the
records that meet those criteria are displayed in a DYNASET. (Dynaset-The answer given by a
query)
Relational operators
< -- Less than
> -- Greater than
>= --Greater than or equal to
<= --Less than or equal to
< > --Not equal to
= -- Equal to
Logical Operators
AND, OR and NOT
NOT –Used to exempt records not to be displayed i.e. Avoids records from been displayed.
Example:
NOT 6000 –displays all records except for those people who early 6000.
Nb: The above examples are made on assumption that there’s a table containing people’s salary.
NOTE:
Wildcards can also be used to search for records you can’t remember but you have an idea.
Wildcards are special symbols (Usually asterisk (*) and question mark (?)) used in place of other
characters:
Example:
Like Pa? –displays all names starting with pa.
Like */*/2006---Displays all records made in 2006 regardless of the date and month.
Running a Query
To run a query in design view, click the Run button on the tool bar (!) OR click “Run” From
“Query” Menu.
b. One-to-many relationship:-For a particular field in one table. This is the most common relationship.
Example:
A person makes one order or several orders.
For instance, there is only one table with the person’s details yet there are several records
related to the same person in the orders.
c. Many-to-many relationship:-For particular records in one table, there are several matching records
in other table and vice versa. This relationship is not very common.
Defining relationships between tables
i. Open the database
ii. From “Tools” menu choose “relationship”
iii. Select the tables to add and click the “Add” button.
iv. To create the relationship, click the common field and drag it to the second table.
N.B
The fields used to create relationship should be of the same data type and properties.
Referential Integrity- Ensures that all records entered in a related table exist in the primary
Enforcing referential integrity table
- Right click the line joining the relationship then click” Edit”
- Check the “Enforce referential integrity” and click OK.
a) Password protection
Password protected database displays a dialog box that requests the password for opening.
To setup a password
i. Open the database in exclusive made
ii. On the tools menu ,click “security” then “set database password “
iii. In the password box ,type the password
iv. Re-enter the password in verify box then click”OK”