Beruflich Dokumente
Kultur Dokumente
Management
[251 Campbell/Wood & 267 Cato]
What is a Database?
A Database simply is a collection of related records or data. The concept of a
database is simple: to gather a set of information of specific interest that is all
related. Examples of databases include: Telephone directories, a Library Card
catalogue and a students permanent record. A Telephone directory, for example,
contains datanames, address, and phone numbersthat are related.
On the far right, you type in a name for the database. The default extension for a
database created in Access is .accdb.
Database structure
A database in Access is made up of Tables. A Table is laid out similarly to a
spreadsheet, except what we call Columns in spreadsheets, are referred to as
Fields in a database. As with a spreadsheet, each column has a heading, called
the Field Name. A field name can be up to 64 characters long, including spaces.
A table stores records that form part of a related group. These related groups are
called entities. An entity is any type of data that has importance. For example,
a supermarket stores data about its stock, its employees, its suppliers, and so on.
Each is an entity, and the data related to those entities will be stored in tables.
Table Table
Record
Table
The structure of a database
Field Field Field Field Field
Record
The figure above shows a single record with five fields. This data can be
represented as a tuple. A tuple is a series of elements where you know how
many elements there are in the series. Here is the record above written as a
tuple:
Keys
Tables need keys. A key is a field in a table that is used to identify the record in
some way.
In this table the best choice for a primary key would be the ISBN field,
because this number is unique to each book. There is another candidate
key in this table, a composite key created from the fields Book Title and
Author. This combination could be unique enough, as it is unlikely the
same author has written two or more books with the same title if we
assume that revised editions have the edition number in the title. If you
select the ISBN as the primary key, the combination of Book Title and
Author would be a secondary or alternate key, because it is a candidate key
that is not being used as a primary key.
Stock Orders
Book title ISBN
Author Order Number
ISBN
Supplier
Number in
Number
stock
ordered
Date ordered
The relationship between Stock and Orders
Data types
Note: If the employee number contains letters and numbers (alpha numeric) you
would choose Text as the data type.
If you have tuition, fees, or any field that contains money, choose the currency
data type. Also, ensure that format also contains currency, and not general, in
order for the $ dollar sign to show automatically.
Commonly Used Data Types
Textthe Text data type is used when you plan to store either
a) Alphabetic characters, meaning words, and
b) AlphaNumeric characters, meaning a combination of Words and Numbers.
Example, you would use a Text data type for a field containing surnames,
firstnames, middle names, Countries, etc..
You would also use a Text data type for a field containing Serial numbers,
Addresses, for example 12, elm drive, Zip Codes, Years, etc.. If you do not specify
these as being of Text data type, the computer will interpret them as calculable
fields.
Numberas it implies, a Number data type will be given to a field containing
numeric data. E.g. for fields that contain stock information, number of vehicles
involved in an accident, etc.
Memothis allows you to enter large amounts of text in a field. You can format
this kind of text by adding colour or changing the font.
Date/Timethis is used for storing the date or time. If you select it, you can use
a date picker when you enter dates into records. The date picker is a small
calendar that allows you to select the date rather than type it out.
Curencythis is for fields where you want to enter values in a currency. The
currency depends on the currency you have stored in your system settings.
Yes/nothis type of data creates a checkbox in the field. Selecting the checkbox
indicates yes.
Hyperlinkthis type of data is for creating hyperlinks, which link to other pages
or to web pages on the Internet.
The first thing you do is open Microsoft Access. You do this by going to programs,
and clicking the Microsoft Access icon. You can also open access by clicking run,
then typing in msaccess or access, then your enter key.
When in Access, choose blank database, since it is a new one that you are about
to create.
Give it a name, then click on create.
Next, Maximize your database area, by clicking on the Maximize button. It is the
middle, square button.
Blank database template
Most of the features you will need for creating and modifying fields and data
types are on the Table Tools [Datasheet] tab.
To work in Access, you need to be able to view the data in a number of ways. This
allows you to modify the database structures. By default, a new table in a new
database will be in Datasheet view. This view allows you to add and edit the
records in a field and view all the data stored in a table.
To edit field properties, use Design view. To switch between the views, go to the
Views group on the far left and click the View drop-down button. Select the type
of view you want to use. The two views you will use the most are Datasheet view
and Design view.
.
Tables
Creating fields
To begin creating fields, follow these steps:
1. In design view, type the field name.
2. Choose an appropriate data type.
3. Set the field size [if necessary].
4. Set the format [if necessary].
5. Set the maximum number of decimal places, if necessary.
6. If the field is the primary key, right-click on its row and click Primary Key.
You can also create tables by importing spreadsheets. You are always asked to
create at least one of your Database tables by importing a spreadsheet in your
SBA.
1. Click on the External Data tab, then the Excel button. This will bring up the
Import Spreadsheet Wizard.
2. Browse to the location where your file is located and select the spreadsheet
that you would like
to import.
3. Click OK.
4. In your Import Spreadsheet Wizard you should be able to see the columns of
your spreadsheet in the Sample data for worksheet sheet 1.
5. Click Next.
6. Tick the box that says First row contains column headings. If you do that
the information in the first row, or the information in the first row of each
column, will become the headings or field names.
In the example, Project, 2002, 2003, 2004 and 2005 Row 1 of columns,
A, B, C, D and E respectively, were you to choose First row contains column
headings, they would become the field names in your new database table. See
the example below.
7. In where would you like to store your data, UNLESS you are told to add, or
append it to an existing table, click IN a new table.
8. If you are told not to import a field click do not import field (skip), but under
ordinary circumstance, just click next.
9. If not told to add a primary key, click No primary key.
10. Click Next.
11. In Import to table type in the name that you were told to give to your
Table.
Sorting
The same rule applies in Access as it does in Excel. Select the column, highlight
everything then click the sort buttons.. Ascending shows a-z, descending z-a.
Creating relationships between tables
In a relational database, which is the official name given to the structure of an
Access database, relationships must be made between, and among, tables, for
the database to be effective, and serve its function adequately.
Do NOT assume that identical Field Name means identical information. I advise
you to open your tables and compare the Data and the Fields based on what is
contained in them, and not by their names.
To create a relationship
You can create a relationship by navigating to the Database Tools and selecting
the relationships button, OR by clicking on the relationships icon. It is an icon
showing 3 tables.
Relationships button
After choosing the tables that you want to create the relationships between or
among, ensure that you know the information that is similar, and the fields in
which that similar information is located.
Next, Click the first field name, and holding down your left mouse button, drag it
and select the field name in the other table, to which you want to create the
relationship on. Repeat the steps, depending on the number of tables that you
have. Click Create.
Again, remember you can only create a valid relationship between similar data
fields. After doing that, save the relationship.
When a relationship is created between tables, a plus sign (+) appears to the left
of the data field. Clicking on the field expands it, and you should see information
that is related to the current table in the other tables.
Creating a query
First, a definition of a query. A Query is a way of bringing data from more than
one table together. It is like filtering except that it is often used when you want to
alter or update that subset of data too. It also differs from filtering in that the
results are returned on a separate tab, not on the table itself. A query is stored as
an object that forms part of your database, so you can save it and return to it for
editing if you need to.
You can create different kinds of queries by creating criteria for them:
Select query: use this type of query to find and display a subset of data.
Creating a select query is similar to creating a filter.
Delete query: use this type of query when you want to delete a record
or sets of records.
Update query: use this type of query to edit or update the data in a
group of records.
Append query: use this type of query if you want to run a query and
insert the results at the end of an existing table.
Make-table query: this type of query stores the results of the query as a
new table in the database.
You can create queries on the Create tab in the Other group.
The simplest type of query is a select query. Suppose you want to create a select
query that shows the records from the Registry table showing all the gifts that
begin with the letter C
2. A Query tab opens in Design view. In the Show Table dialogue box, select the
tables you want to use in the query. In this case you want the Registry table
so you select it and click the Add button. Click Close when you have finished.
3. In the Query Type group you can select the type of query you want to create.
The default type is Select, which is what you want in this case.
4. In the query grid, select the fields you want to add using the drop-down lists in
the Field row. Once you have selected each field, the Table row lists in the
Field row. Once you have selected the desired field/fields the Table row is
automatically populated with the name of the table where the field comes
from.
5. The checkboxes in the Show row are for indicating whether you want the field
to display in the results. In this case you want them to display, so you check
all the checkboxes.
6. In the Criteria row type enter C*. This will output all items that begin with the
letter C.
7. To actually view the results of your query, you need to run it. You do this by
navigating to the Design tab and clicking run.
8. Your results are going to be displayed.
Calculated fields
You can use queries to calculate values based on other fields. For example, you
may want to calculate the total amount of sales you have made. To do this, you
create a calculated field, which is a field created purely for storing the results of
calculations. If you use the values stored in other fields to carry out calculations,
you enclose the field name in square brackets when creating the formula, like
this:
Area:[Length]*[Breadth]
The calculated field is Area. It uses existing fields Length and Breadth to
calculate the area.
You want to create a query that shows the albums ordered and paid for so far.
You then want to calculate the tax on each of those albums, assuming the tax
rate is 10%. You will have to create a calculated field to store the tax amount.
Access also has tools known as aggregate functions. These are functions that
allow you to calculate the sum, average, count, maximum and minimum in a
series of values:
Sum finds the total average in a series of values.
Average finds the average in a series of values.
Minimum finds the lowest value in a series of values.
Maximum finds the highest value in a series of values.
Count counts the number of values in a series.
Using the Expression Builder
You can use the Expression Builder to help build expressions. The Expression
Builder is a tool you can start from most places in Access where you write
expressions, such as control properties in forms and reports, field properties
in tables, and in the query design grid. It offers easy access to the names of
fields and controls in your database, as well as many of the built-in functions
available to you when writing expressions.
Expression box
The upper section of the Expression Builder contains an expression box where you
construct your expression. You use the three columns in the lower section of the
Expression Builder to locate elements that you can paste into the expression box.
You can also type parts of the expression directly into the expression box. Thus,
you can construct an expression by combining some amount of typing and
pasting.
Operator buttons
The middle section of the Expression Builder displays buttons for commonly used
operators. To insert an operator in the expression box, click the appropriate
button. To display a list of operators you can use in expressions, click the
Operators folder in the lower-left column, and then click the appropriate category
in the middle column. The lower-right column then lists all of the operators
available in the selected category. To insert an operator, select it and click Paste.
Expression elements
The lower section of the Expression Builder contains three columns.
The left column displays folders that list the tables, queries, forms and reports in
your database, as well as the available built-in and user-defined functions,
constants, operators, and common expressions.
The middle column lists specific elements or categories of elements for the folder
selected in the left column. For example, if you click Built-In Functions in the left
column, the middle column lists function categories.
The right column lists the values, if any, for the elements you selected in the left
and middle columns. For example, if you click Built-In Functions in the left column
and click a function category in the middle column, the right column lists all of
the built-in functions available in the selected category.
You construct your expression by typing text and pasting elements from the other
areas within the Expression Builder into the expression box. For example, you can
click on the lower-left column to see any of the objects in your database, as well
as functions, constants, operators and common expressions. When you click an
item in the left column, the content of the other columns (middle and right)
changes accordingly.
For example, when you click the name of a table in the left column, the middle
column lists the fields in that table.
When you double-click Functions and then click Built-In Functions, the middle
column lists all of the function categories, and the right column list the functions
themselves.
After you insert a function into your expression, the expression box displays both
the function and text indicating the arguments that the function needs. You can
then replace that text with the correct argument values.
When you paste an identifier into your expression, the Expression Builder only
inserts the parts of the identifier that are required in the current context. For
example, if you start the Expression Builder from the property sheet of the
Customers form and then paste an identifier for the Visible property of the form
into your expression, the Expression Builder pastes only the property name
Visible. If you use this expression outside of the context of the form, you must
include the full identifier: Forms![Customers].Visible.
To start the Expression Builder in a table, form or report
Click the property or action argument box that will contain the expression.
Click the Build button next to the property.
To start the Expression Builder in a query
Click the cell in the design grid that will contain the expression. For example, click
the Criteria cell for the column where you want to supply criteria, or the Field cell
for the column where you want to create a calculated field.
Click the Build button on the toolbar.
You can think of the Expression Builder as a way to look up and insert things you
might have trouble remembering, such as identifier names (fields, tables, forms,
queries and so on) and function names and arguments.
The Query Setup group on the Design tab
Wildcard characters
A wildcard is a special character that can represent one or more characters in a
text value. You can use wildcards to find many records with similar, but not
exactly the same, information. You can also use them to look for a specific record
when you can't remember enough information to retrieve just that one record.
# 1: Match characters in a specific position
The most flexible wildcard character is the asterisk (*). It matches any character
or any block of characters in a specific position. For instance, the following
statement would return any entry that contains the string access without regard
to letter case:
Like "*Access*"
So it would return the following entries: Microsoft Access, Access 97,
and accessing.
Drop the first * character to match entries that begin with the string access:
Like "Access*"
This statement would return Access 97 and accessing but not Microsoft Access.
Similarly, the following statement would return Microsoft Access but not Access
97 or accessing:
Like "*Access"
# 2: Spaces matter in a * match
When using the * character to match characters in a specific position, pay close
attention to space characters. If the search string includes a space character
between the literal characters and the * character, Access will return only those
entries that include a space character in that position. For instance, the following
statement matches Microsoft Access but not Access 97 or accessing:
Like "* Access".
You might not expect that search string to return Access 97, but the absence of
the wordaccessing might be a surprise. Access won't return accessing because
the entry doesn't have a space character before the access block. Similarly, the
following statement matches Access 97 but not Microsoft Access or the single
word entry, accessing:
Like "Access *"
# 3: Match just one character in a specific position
The question mark character (?) serves as a single-character placeholder. You can
combine this wildcard to specify a certain number of characters. For instance, the
following statement would match Smith and Smyth but not the
word smooth (without regard to letter case):
Like "Sm?th"
You can combine ? characters to cast a wider net or to focus the search,
depending on the circumstances. For example, the following criteria would
find Smith, smile, smite, and smirk:
Like "Smi??"
It would not find smirch or smitten. That's because each ? character represents
only one character. Although both smirch and smitten match the literal characters
in the expression (smi), both words have more than two characters following
those literal characters. To catch all entries that begin with smi without regard to
the number of characters, use the * character (# 1).
Creating a Report
To create a report, select Report Wizard on the Create tab. Click on the reports
button in your main database menu. Choose create report by using wizard,
because its more user-friendly. Choose where you want to information that you
want to use in your report. That is, whether you want it from tables, queries, or a
combination of the two.
Choose the desired fields, add them by using the > sign. Click next.
Sort your records. (You are typically given the field or field on which your report
has to be sorted.)
Choose the layout that you want for your report, and the page layout, whether
you want it to be portrait or landscape orientation. Choose the style that you
want for your report.
Click next.
Click finish.
Update Query
A query can be used to update all records that satisfy given criteria by performing
some operations on existing values in the table. It makes a permanent change to
a group of records, or to all records, in one or more tables.
Creating an update query
1. In the database window, click on the Queries object and double-click on
Create query in Design View.
2. The Design View is displayed along with the Show Table dialog box.
Select the table that is to be updated and click on Add. Click on Close.
3. Insert the fields required or the query and add any necessary criteria to
select the records to be updated.
4. Click on the query menu and choose update query.
5. Click on the update to box for the field that is to be updated.
6. Build the expression in the update to field and create the expression
needed.
7. Click run, BUT BEFORE YOU DO REMEMBER THAT YOU CANNOT UNDO
AN UPDATE QUERY. DO IT ONLY WHEN YOU KNOW YOUR
INFORMATION IS CORRECT.
8. View the table to see whether the records have been updated.
Suggestion: Always do a trial run of an update query on a copy of the table. If the
results are what you want, delete the copy of the table and run the update query
on the real table.
Key terms
You can use a range of operators to create criteria for your queries. Note that if
you use letters or symbols as criteria, you should enclose them in quotation
marks. For example, if you want to create a condition that only albums
calledOasis are displayed, you type Oasis in the Criteria row of the Album field.
You can also use these operators when creating expressions for filters.