How to build a single file database
This tutorial guides you through building a simple, single-file
database. In a single-file database, also known as a flat-file database,
you put all your information into a single table. This is the simplest
form of database to create, but it has some limitations and disadvantages.
The most important of these limitations are that single-table databases
are incapable of representing some real-world data and they create more
work when it comes to data entry.
When a single
file will do
Having said all
that however, there are some applications where a single-file database
is all you need. For example, if you’re dealing with small quantities
of information, it may not be worth your effort to design a relational
database. You may prefer to create a simple all-in-one table and put
up with any additional typing this necessitates.
In this tutorial
we’re going to use Access to create a flat-file membership database
from scratch.
Creating
the table
1.
Open Access and in the initial dialog box, select Blank Access
Database and click OK. (Clicking the other option will give
you the opportunity to utilize some of the premade databases that Access
offers - you can use these as are or modify them to suit your needs)
But
my table looks different when I reopen it.
Access
gives you different ways to view your objects. Remember when we created
the Members table - we had several options on how to create the table.
Access still gives you these options for accessing your objects even
after they are created.
Design
view gives you the screen that we used initially to enter our
fields for our table. After you finish creating your table you can go
back to viewing the table in design view in order to change the table,
ie. add another field, make a field size larger, redefine a field's
data type, etc.
Datasheet
view gives you your table in a spreadsheet format. This is
useful when you want to view many records from your database at the
same time. Some also find it useful for entering data into your table
instead of using a data entry form.
You
can easily and quickly switch between these two views by opening the
View pull down menu from the tool bar (shown below).
What have
we done?
You now have a
Members table ready for you to enter information.
Before we take the
next steps – cleaning up the data formatting and thinking about
improving the data structure – let’s analyze what we’ve
done so far.
To create our table,
we defined a field for each item of information we want to store. The
choice of fields was mostly common sense, although a couple bear closer
examination.
We broke each member’s
name into two parts: first name and last name. This allows us to sort
and search our database using either of those fields.
Similarly, we broke
the address into component parts to give us a structure which lets us
sort, search and group members by province, postal code and city/town.
This division will also make it easy when we want to print address labels
or envelopes. If you put the address all in one field, it becomes a
very difficult task to create mailing labels which have the name on
the first line, the address on the second line, and so on.
This breaking down
of data into usable component parts is a vital step in creating a useful
database.
Data types
Each field we’ve
included has its own data type. The data type defines the type of information
which may be stored in a field. The majority of our fields are text
data type. Text fields can hold alphanumeric information, including
letters, numbers, spaces and punctuation marks.
Other common data
types include numeric (also known as number), currency (a specialized
form of numeric field), date/time, Boolean (also called Yes/No), hyperlink,
memo (for storing large quantities of text) and picture/object. Not
all database programs support all these data types and our simple data
structure uses only four types: text, numeric, Boolean and date.
Boolean fields are
logical fields which may contain either a 0 or 1, or another binary
pair such as True/False or Yes/No. They’re useful when you want
Yes/No answers to questions. We’ve used them in our database in
the ListHomePhone, ListWorkPhone, active and FeesPaid fields to answer
the questions “Should I list the member’s home/work number
when printing reports?”, “Is this an active member?”
and “Are the member’s fees up to date?”
Notice how we’ve
used the text data type for phone numbers. Why not use the numeric data
type? The simple rule of thumb when choosing numeric field types to
remember is - am I going to be doing calculations with these numbers.
With phone numbers,
the answer’s obvious. Besides the fact that phone numbers are
not standard numbers, that is they may contain spaces and often have
non-numeric characters such as ")" or "-". Also,
you would never think of doing numeric calculations on phone numbers
such as adding them together.
What about American
Postal Codes - text or numeric? Although this field will contain only
numbers, we don’t treat postal codes as numbers, that is, use
them in numerical calculations. Because of this, and because of the
way database sort and format numbers differently from text, always store
this type of information in a text field.
Field sizes
Why is each field
the size it is?
The most important
thing about the size of your fields is that you make them big enough
to accommodate the largest possible piece of information they will need
to store.
With names and addresses,
be generous. You may not be able to imagine a family name longer that
15 characters, but Ms Clarissa Worthington-Wettersley is going to be
really annoyed when all her club correspondence is addressed to Ms Worthington-Wet.
As for fields where
you’re not quite sure how much info you need to store, such as
the Skills field we’ve included, one approach is to allow the
maximum permissible size for a text field, which is usually around 254
or 255 characters. Another approach is to use a memo data type. This
type of field allows for text of almost any length to be entered.
A word about
field names
You’ll notice
that many of the field names are compound words, such as FirstName and
MembershipType. Why is that so? Why not make them more readable by including
spaces?
Well, although the
major database programs allow you to create field names which contain
spaces, if you end up using your database with scripting tools such
as JavaScript or with advanced data access technologies, you’ll
find spaces in fieldnames are unacceptable. So, even if you don’t
think you’ll end up using such complex resources, it pays to allow
for the possibility by eliminating spaces.
When it comes to
creating data entry forms, you can always change the field name which
is displayed above a data entry box by adjusting its caption.
Formatting
and validation
We’ve created
our database with almost no validation or formatting. The only exception
is that we’ve made the MembershipNumber unique by making it a
primary key field. In an upcoming tutorial we will go through how to
apply formatting aids to this database.