Database Management (Primary - Keys, Relationships - Forms - Queries)
Database Management (Primary - Keys, Relationships - Forms - Queries)
Management
Objectives
• Establishing Primary Keys in Database • Create Reports
• Establish relationships: show the joins • Use of report wizard
Jens Martensson
between tables (one-to-one and • Use of sorting and grouping
one-to-many) • Use of statistical and summary features (count,
sum and average
• Create and manipulate Forms • Generate report to screen, printer and file
• Use of form wizard • Rename Report title
• Select suitable fields and use of sub-form
• Create Queries
• More than one criterion
• Use of select
• Use of calculated field
• Use of two or more fields involving the use of
2
relational and logical operator
Jens Martensson
Establishing
Primary Key
3
Primary Key
• A primary key is a field whose values are unique so they can be used
to identify a particular record in a table.
Jens Martensson
• A foreign key appears in a table where it doesn’t really belong but
allows two tables to be linked.
4
Primary Key
How to create a primary key?
Jens Martensson
table.
2. Select the field and click the “Primary
Key” command.You can also right-click a
specific field and make it the primary key.
5
Jens Martensson
Establishing
Relationships
6
Relationships in Database
What’s a relationship ?
• A relationship in Access helps you combine data from two different tables. Each
Jens Martensson
relationship consists of fields in two tables with corresponding data.
7
Relationships in Database
• Relationships allows the database system to • One to One Relationship:
automatically retrieve the data from • Is when one record in the first table matches
multiple tables to answer our queries (a zero or one record in the second table.
method of retrieve information from a • For example, one customer is only renting one
database) vehicle.
Jens Martensson
• One to Many Relationship:
Types of Relationships: • Is when one record in the first table may match
many records in the second table.
• For example, one customer can rented many
• One-to-one Relationship vehicles.
• One-to-many Relationship
NB: It is possible to create a many-to-many
relationship.This is when many records in the
first table match may records in the second
table.This type of relationship must be avoided
because it may allow your database to not
8
function properly.
Relationships in Database
How to create a relationship ?
Jens Martensson
the ribbon.
2. Select the “Relationship” command.
3. On the Relationships Design tab, in the
Relationships group, click “Add Tables”
4. Select the tables and then click “ADD”
5. Drag a field (typically the primary key)
from one table to the common field (the
foreign key) in the other table.
9
Jens Martensson
Create and
Manipulate
Forms
10
Forms
• A form is a user-friendly interface to a database system. Forms can
be used for inputting data or simply viewing data in a user-friendly
way.
Jens Martensson
• Simple forms are based on a single table but complex forms that are
based on two tables are particularly useful when viewing large
amounts of data.
Jens Martensson
form for.
2. Navigate to the “Create” tab and then
select the “Form Wizard” command.
3. Move all the fields onto the “Selected
Fields” section.
4. Accept all other defaults until the wizard
closes.
5. To view the form. Click on the form and
then select the view option you require.
13
Forms
Sub-forms How to create a sub-form?
• A sub-form will be a form that links to the 1. Select the tables that would be inclusive in
Jens Martensson
main form for a particular database. the form.
• For example, we would have a customer table 2. Ensure that you moved all fields
that has all the persons who rented a car. The associated with both tables to the
Vehicle table will contain information if a
particular customer rented multiple vehicles.
“Selected Fields” category.
• A sub-form would allow you to view this 3. Accept all other defaults until the wizard
information. closes.
4. Save if prompted to do so.
14
Jens Martensson
Create Queries
15
Queries
What are queries?
Jens Martensson
Queries answer the questions that user pose.
• In other words, a query can either be a request for data results from
your database or for action on the data, or for both.
Jens Martensson
the “Query Design” command.
2. Add the table or tables and then the fields
you want to appear in the query by
clicking in the next free field and choosing
the field from the drop-down menu.
3. In the Criteria row and add your criteria.
4. To run the query, look for “Run” or the
run symbol.
5. The results of the query will be displayed.
18
Queries
Calculated Fields in Queries
Jens Martensson
values from other table fields.
19
Jens Martensson
Create Reports
20
Reports
• Reports offer a way to view, format, and summarize the information
in your Microsoft Access database.
Jens Martensson
• A report is a database object that comes in handy when you want to
present the information in your database for any of the following
uses:
• Display or distribute a summary of data
• Archive snapshots of the data
• Provide details about individual records
• Create labels
21
Jens Martensson
22
Reports
How to create a report?
Jens Martensson
the “Report Wizard” command.
2. Add the tables or queries, and then the
fields that you want to appear in the
report.
3. Select any grouping that you want to be
applied to the report.
4. Select any sorting and any summary
options that you want to be applied to
the report
5. When the wizard finishes, the report is 23
displayed.
Reports
• Once the report is generated, you can sort • If you wish to rename the title of your
the information in ascending or descending report, simply double-click the title name
order. and make the necessary changes.
Jens Martensson
• You can use summary features such as:
• SUM
• COUNT
• AVERAGE
24
Jens Martensson
25