Beruflich Dokumente
Kultur Dokumente
Level II
LEARNING GUIDE # 1
This learning guide was developed to provide you the necessary information regarding the
following
Opening and designing DB application and principles
Creating DB objects
This guide will also assist you & you will be able to
Learning Activities
1. Read the specific objectives of this Learning Guide.
4. Submit your accomplished Self-check1. This will form part of your training portfolio/range.
5. Read the “Operation Sheet 1& 2” and try to understand the procedures discussed.
6. Do the “LAP test” (if you are ready) and show your output to your teacher. Your teacher will
evaluate your output either satisfactory or unsatisfactory. If unsatisfactory, your teacher shall
advice you on additional work. But if satisfactory you can proceed to Learning Outcome 3.
Information Sheet-1 Creating Database Tables
Creating DB Tables
DB Tables: - Recently, we define it as a file but technically, it was defined as a container or a
worksheet-like container where the collection of data has been stored.
Before we proceed to creating your first table, we need to know first the basic components of a
table:
Meta Data – Database Structure
Field – Column – Data
Field name
Record - Row - Information
Metadata – is a “data about data” or synonymously called table structure that defines what
type of data your data is?
Given these data:
(1) “Noel” which is a firstname, we can say that it composes of texts, so we define the
firstname to accept text only thus it accepts the value “Noel”
(2) Supposed that “21” is the Age of Noel, then we will define Age as a number,
specifically an Integer so it will only accept a value which is an integer.
Thus it gave a table structure of:
Field Name Data Type
Firstname Text
Age Integer
Which only means to say that you cannot enter a number value in the Firstname field,
likewise you cannot enter a text value to the Age field?
In that case, entering a number value to a Firstname field would treat it as text. Ex:
Richard23. And cannot be used for computation.
Field – Every column in a table represents a field by which data has been stored.
Fieldname – This refers to the name of every field.
Records –Every row in a table represents a record, which is a collection of meaningful data.
Example of a table
Table name: StudentsTable
7 columns = 7 fields
Fieldnames
“MOE-0001” is the data for IDNumber field. And IDNumber is a fieldname for that data.
When creating a table, one will need to specify what kinds of data are to be
stored in this field.
The different kinds of Ms Access2007 data types are:
Text: allows for the storage of any kind of data, characters, digits and special characters.
It has a defect length of 50 characters with a maximum length of 255.
It is normally used to store data (short) such as names, addresses, or any number
not used in calculations, like telephone numbers or zip codes.
Memo: is used for texts of more than 255 characters such as comments or explanations.
The Memo data type can hold somewhere around 65000 characters if you enter
them through the Access interface and 1 Gigabytes if you enter the text
programmatically.
Long text like article body text, blog posts, long descriptions
Fields of the Memo data type can be configured to contain Rich Text. Rich Text is
text to which formatting like bold and italic can be applied.
Access recommends that to store formatted text or large documents, rather to
create an OLE Object field than a Memo field.
A field's data type does not only determine the type of data you can put in.
It also determines the properties you can set on the field as you will see in the next sections.
The Field Properties can be found by viewing your table in Design View and selecting one of its
fields. The Field Properties are at the bottom of the screen.
Property Explanation
The maximum number of characters you can enter. The largest maximum you can set
Field Size
is 255.
Input mask In input mask is a pattern that all data entered in this field must adhere to
Validation A rule that validates the input. Read more on validation rules in the validation rules
rule tutorial.
Indicated whether a value is required for this field. Access will show an error
Required message and won't insert the new record if you try to insert a new record that has no
value for a required field.
Allow Zero
Indicates whether you are allowed to insert a text that contains zero characters.
Length
Apply an index when you want to allow for fast searching on the field's contents or
Indexed when you want to impose a unique constraint (Select "Yes, no duplicates") on the
field.
The properties of the Memo data type are very similar to the field properties of the Text data
type, so I won't describe them again.
The Text Format property lets you choose between Plain Text and Rich Text.
When creating a new Number field the Field Size property defaults to Long Integer. So by default,
the Number field can contain whole numbers.
The Field Size property of the Number data type lets you choose a number type for the field. Below
are the characteristics of each type.
Field Size Explanation Precision
Integer The Integer field stores whole numbers between -32.768 and 32.767. -
The Long Integer field stores whole numbers between -2.147.483.648 and -
Long Integer -
2.147.483.647.
The Decimal field is used for storing decimal values. It has the largest
Decimal precision of all Number fields. The properties of the Decimal field will let you 28
choose the total precision (max 28) and the number of decimal places.
For numeric floating point values that range from -3.4 x 1038 to +3.4 x 1038.
Single The Single data type has a precision of 7 and is best not used for calculations 7
that require a high level of precision.
The Double data type stores numbers between -1.797 x 10308 to +1.797 x
Double 12
10308
The most common Field Size values are probably Long Integer and Double.
In the field properties of a Date/Time field you can pick a format for your date field.
Note that what appears in the Format select list is dependent on your computer's region and
language settings.
One other nice feature of the Date/Time data type is the Show Date Picker property. When
enabled (by selecting "For dates") Access will show a date picker in the data sheet when a date
cell is selected.
In the Field Properties panel of a Currency field you will find a Format dropdown box with a
number of predefined formats. Just like with Date/Time values, the formats that show up here are
dependent on your computer's region and language settings.
When you create a new table in Access, Access automatically inserts an AutoNumber primary key
field called ID for you.
The Yes/No data type
Table wizard
Design view
Creating Tables using design view
Creation of a table by design view is a user customized way of making data storage tables.
Each field in the design view of a table corresponds to a column in the datasheet view of a table.
Designing a table involves:
Entering unique names of the columns of the table in the “field name” column of the design
view. N
Names of fields and objects in Microsoft Access can be up to 64 characters long.
They can include any combination of letters, numbers, spaces, and special characters except a
period (.), an exclamation point (!), an accent grave (`), and brackets ([ ]). They also can't begin
with leading spaces.
Normalization
Normalization is the process of efficiently organizing data in a database.
There are two goals of the normalization process:
1. Eliminating redundant data (for example, storing the same data in more than one table) and
2. Ensuring data dependencies make sense (only storing related data in a table).
Both of these are valuable goals as they reduce the amount of space a database consumes and
ensure that data is logically stored.
The Normal Forms
The database area has developed a series of guidelines for ensuring that databases are
normalized.
These are referred to as normal forms and are numbered from one (the lowest form of
normalization, referred to as first normal form or 1NF) through five (fifth normal form or 5NF).
In practical applications, you'll often see 1NF , 2NF , and 3NF along with the occasional 4NF.
Fifth normal form is very rarely seen and won't be discussed in this article.
First normal form (1NF) sets the very basic rules for an organized database:
Eliminate duplicative columns from the same table.
Create separate tables for each group of related data and
Identify each row with a unique column or set of columns (the primary key).
Do not use multiple fields in a single table to store similar data.
Second Normal Form (2NF)
Second normal form (2NF) further addresses the concept of removing duplicative data:
Meet all the requirements of the first normal form.
Remove subsets of data that apply to multiple rows of a table and place them in separate
tables.
Create relationships between these new tables and their predecessors through the use
of foreign keys.
Create separate tables for sets of values that apply to multiple records.
Relate these tables with a foreign key.
Records should not depend on anything other than a table's primary key.
The Boyce-Codd Normal Form, also referred to as the "third and half (3.5) normal form", adds
one more requirement:
Meet all the requirements of the third normal form.
Every determinant must be a candidate key.
Student# Class#
1022 101-07
1022 143-01
1022 159-02
4123 201-01
4123 211-02
4123 214-01
4. Third Normal Form: Eliminate Data Not Dependent On Key
In the last example, Adv-Room (the advisor's office number) is functionally dependent
on the Advisor attribute.
The solution is to move that attribute from the Students table to the Faculty table, as shown
below:
Students:
Student# Advisor
1022 Jones
4123 Smith
Faculty:
Smith 216 42
Table Relationship
Newcomers to the world of databases often have a hard time seeing the differences between a
database and a spreadsheet.
They see tables of data and recognize that databases allow you to organize and query data in
new ways, but fail to grasp the significance of the relationship that gives relational database
technology its name.
Relationships allow you to describe the connections between different database tables in
powerful ways.
Once you’ve described the relationships between your tables, you can later leverage that
information to perform powerful cross-table queries, known as joins.
A relationship is a logical connection between two tables.
Keys are fields that are part of a table relationship. There are two kinds of keys
1. Primary key 2. Foreign key
1. Primary key
A table can have only one primary key.
A primary key is used to identify each record that you store in the table.
It will not allow a duplication of the Primary Key thus make it unique.
Primary Key is the unique identification of one record. There is a uniquely identification
number, such as
ID number
A serial number
A code that serves as a primary key
Example: - You might have a customer table where each customer has a unique customer id
number. The customer ID field is the primary key of the customer table.
2. Foreign key
A table can also have one or more foreign key.
A foreign key contains values that correspondent to values in the primary key of another table
You use table relationship to combine data from related table
Customer Employee
c-id e- id
c-name e- name
c-age e- age
c-sex e- sex
c-phone e- address
c-address e- salary
c-id
Primary key
Foreign key
There are three different types of database relationships, each named according to the number
of table rows that may be involved in the relationship.
Each of these three relationship types exists between two tables.
1. One-to-one relationships: occur when each entry in the first table has one, and only
one, counterpart in the second table.
One-to-one relationships are rarely used because it is often more efficient to simply
put all of the information in a single table.
2. One-to-many relationships: Is the most common type of database relationship.
They occur when each record in the first table corresponds to one or more records
in the second table but each record in the second table corresponds to only one
record in the first table.
For example, the relationship between a Teachers table and a Students table in an
elementary school database would likely be a one-to-many relationship, because
each student has only one teacher, but each teacher may have multiple students.
3. Many-to-many relationships: occur when each record in the first table corresponds to
one or more records in the second table and each record in the second table corresponds
to one or more records in the first table.
For example, the relationship between a Teachers and a Courses table would likely
be many-to-many because each teacher may instruct more than one course and
each course may have more than one instructor.
Benefit of using relationship
For example, the elements writer, novel, and consumer may be described using ER diagrams
this way:
In the diagram, the elements inside rectangles are called entities while the items inside
diamonds denote the relationships between entities.
This ER diagram tutorial for beginners covers most things related to ER diagram, for quick
navigation use the links below.
ER Diagram Usage
ER Diagrams Symbols and Notations
How to Draw ER Diagrams
ER Diagram Templates
Benefits of ER Diagrams
ER Diagrams Usage
ER diagrams are most often associated with complex databases that are used in software
engineering and IT networks.
In particular, ER diagrams are frequently used during the design stage of a development
process in order to identify different system elements and their relationships with each other.
For example, inventory software used in a retail shop will have a database that monitors
elements such as purchases, item, item type, item source and item price. Rendering this
information through an ER diagram would be something like this:
In the diagram, the information inside the oval shapes is attributes of a particular entity.
Elements in ER diagrams
1. Entity 3. Relationship
2. Attribute
There are more elements which are based on the main elements.
Derived attribute
Cardinality and ordinalily are two other notations used in ER diagrams to further
define relationships.
Ethiopian TVET System
Training, Teaching and Learning Material
Entity
An entity can be a person, place, event, or object that is relevant to a given system.
For example, a school system may include students, teachers, major courses, subjects, fees, and
other items.
Entities are represented in ER diagrams by a rectangle and named using singular nouns.
Weak Entity
In more technical terms it can defined as an entity that cannot be identified by its own attributes.
It uses a foreign key combined with its attributed to form the primary key.
An entity like order item is a good example for this. The order item will be meaningless without an
order so it depends on the existence of order.
Attribute
For example, the attribute Inventory Item Name is an attribute of the entity Inventory Item. An
entity can have as many attributes as necessary.
For example, the attribute “customer address” can have the attributes number, street, city, and state.
Note that some top level ER diagrams do not show attributes for the sake of simplicity.
Attributes in ER diagrams, note that an attribute can have its own attributes ( composite attribute )
TTLM Development Manual Date: 05-2011 Page 19 of 54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
Multivalued Attribute
If an attribute can have more than one value it is called a multivalued attribute.
It is important to note that this is different to an attribute having its own attributes. For example a
teacher entity can have multiple subject values.
Derived Attribute
For example for a circle the area can be derived from the radius.
Relationship
For example, the entity “carpenter” may be related to the entity “table” by the relationship “builds”
or “makes”.
Relationships are represented by diamond shapes and are labeled using verbs.
Recursive Relationship
If the same entity participates more than once in a relationship it is known as a recursive
relationship.
In the below example an employee can be a supervisor and be supervised, so there is a recursive
relationship.
These two further defines relationships between entities by placing the relationship in the context of
numbers.
In an email system, for example, one account can have multiple contacts.
Chen, UML, Crow’s foot, Bachman are some of the popular notations. Creately supports Chen, UML
and Crow’s foot notations.The following example uses UML to show cardinality.
Below are some ER diagram templates so you can get started quickly.
Clicking on the image and in the new page that opens click the “Use as Template” button.
ER diagrams constitute a very useful framework for creating and manipulating databases.
First, ER diagrams are easy to understand and do not require a person to undergo extensive training
to be able to work with it efficiently and accurately.
This means that designers can use ER diagrams to easily communicate with developers, customers,
and end users, regardless of their IT proficiency.
Second, ER diagrams are readily translatable into relational tables which can be used to quickly
build databases.
In addition, ER diagrams can directly be used by database developers as the blueprint for
implementing data in specific software applications.
Lastly, ER diagrams may be applied in other contexts such as describing the different relationships
and operations within an organization.
3. A container or a worksheet-like container where the collection of data has been stored?
11. That allows you to describe the connections between different database tables in powerful ways.
Self - Check 2
Creating Database Tables
(Answer Key)
1. Table Structure
2. A. 1 to 1
B. 1 to Many
C. Many to Many
3. Database Table
4. Field
5. Data
6. Fieldname
7. Record
8. Primary key
9. A. Design View
B. By using a Wizard
10. Text, Memo, Number, Date & Time, Currency, Autonumber , Yes/No ,OLE Object, Hyperlink
11. Relationship
2. In the File Name box, type a file name for the new database.
3. To browse to a different location to save the database, click the folder icon.
4. Click Create.
The new database opens, and a new table named Table1 is created and opens in Datasheet view.
2. In the Open dialog box, select the database that you want to open, and then click Open.
A new table is inserted in the database and the table opens in Datasheet view.
Contacts A table for managing business contact information, which includes e-mail addresses, Web
page URLs, and attachments, such as a service contract and a photo.
Tasks A table for tracking tasks, which includes a field for attachments.
Issues A table for tracking issues, which includes a field for attachments and an append-only Memo
field that keeps a history of old field values.
Events A table for managing events, which includes a rich text Memo field and a field for attachments.
After you create a table by using a table template, you may want to add fields by using field templates. A
field template is a predefined field that you can add to any table in Datasheet view. For more information
about using a field template, see the section Add a field by using a field template, later in this article.
2. In the Open dialog box, select and open the database in which you wish to create a table.
3. On the Create tab, in the Tables group, click Table Templates and then select one of the available
templates from the list.
A new table is inserted, based on the table template that you chose.
You can create a table by importing or linking to data that is stored elsewhere. You can import or link
to data in an Excel worksheet, a Windows SharePoint Services list, an XML file, another Access database, a
Microsoft Office Outlook folder, and more.
When you import data, you create a copy of the data in a new table in the current database.
Subsequent changes to the source data will have no effect on the imported data, and changes to the
imported data do not affect the source data. After you connect to a data source and import its data, you can
then use the imported data without connecting to the source. You can change the design of an imported
table.
NOTE You cannot edit data in an Excel worksheet by using a linked table. As a workaround, import the
source data into an Access database, and then link to the database from Excel. For more information about
linking to Access from Excel, search Excel Help, or see the links in the See Also section.
2. In the Open dialog box, select and open the database in which you wish to create a new table.
3. On the External Data tab, in the Import group, click one of the available data sources.
4. Follow the instructions in the dialog boxes that appear at each step.
Access creates the new table and displays it in the Navigation Pane.
TIP You can also import or link to a SharePoint list by using a command on the Create tab.
You can create a table in your database that imports from or links to a SharePoint list. You can also
create a new SharePoint list by using a predefined template. The predefined templates in Office Access 2007
include Contacts, Tasks, Issues, and Events.
2. In the Create New List dialog box, type the URL for the SharePoint site where you want to
create the list.
3. Enter a name for the new list and its description in the Specify a name for the new
list andDescription boxes.
4. To open the linked table after it is created, select the Open the list when finished check box
(selected by default).
1. Click Custom.
2. In the Create New List dialog box, type the URL for the SharePoint site where you want to
create the list.
3. Enter a name for the new list and its description in the Specify a name for the new
list andDescription boxes.
4. To open the linked table after it is created, select the Open the list when finished check box
(selected by default).
2. In the Get External Data dialog box, type the URL for the SharePoint site that contains the data
that you want to import.
3. Click Import the source data into a new table in the current database, and then click Next.
4. Select the check box next to each SharePoint list that you want to import.
2. In the Get External Data - SharePoint Site dialog box, type the URL for the SharePoint site
that contains the list to which you want to link.
3. Click Link to the data source by creating a linked table, and then click Next.
4. Select the check box next to each SharePoint list to which you want to link.
Unless you have a specific reason not to, you should specify a primary key for a table. Access
automatically creates an index for the primary key, which can help improve database performance.
Access also makes sure that every record has a value in the primary key field, and that the value is
always unique. Unique values are crucial, because otherwise there is no way to reliably distinguish a
particular row from other rows.
When you create a new table in Datasheet view, Access automatically creates a primary key for
you and assigns it a field name of ID and the AutoNumber data type.
In Design view, you can change or remove the primary key, or set the primary key for a table
that doesn't already have one.
Sometimes, you might already have data that you want to use as a primary key. For example,
you may have existing ID numbers for your employees. If you create a table to track employee
information, you might decide to use the existing employee ID as the primary key for the table. Or,
perhaps employee ID is only unique in combination with department ID, requiring that you use both
fields together as the primary key. A good candidate for the primary key has the following
characteristics:
Each record has a unique value for the field or combination of fields.
The field or combination of fields is never empty or null — there is always a value.
The values do not change.
If no suitable data exists to use as a primary key, you can create a new field to use as a primary key.
When you create a new field to use as a primary key, set the field's data type to AutoNumber to help
make sure that it meets the three characteristics in the preceding list.
1. Select the table whose primary key you want to set or change.
2. On the Home tab, in the Views group, click View, and then click Design View.
3. In the table design grid, select the field or fields that you want to use as the primary key.
To select one field, click the row selector for the field that you want.
To select more than one field, hold down CTRL, and then click the row selector for each field.
A key indicator appears to the left of the field or fields that you specify as the primary key.
2. On the Home tab, in the Views group, click View, and then click Design View.
3. Click the row selector for the current primary key. If the primary key consists of multiple fields, hold
down CTRL, and then click the row selector for each field.
The key indicator is removed from the field or fields that you previously specified as the primary key.
NOTE When you save a new table without setting a primary key, Access prompts you to create a new field
for the primary key. If you click Yes, Access creates an ID field that uses the AutoNumber data type to
provide a unique value for each record. If your table already includes an AutoNumber field, Access uses it as
the primary key. If you click No, Access does not add a field, and no primary key is set.
2. On the Home tab, in the Views group, click View, and then click Design View.
TIP To provide more space to enter or edit a setting in the property box, press SHIFT+F2 to display
the Zoombox. If you are setting the Validation Rule property to an expression and would like help in
building it, click next to the ValidationRule property box to display the Expression Builder.
NOTE For more information about creating a table, see the section, Create a new table.
2. In the Add New Field column, enter the name of the field that you want to create.
Sometimes it is easier to choose from a predefined list of fields that fit your needs than to manually
create a field. You can use the Field Templates task pane to choose from a list of field templates. A field
template is a predefined set of characteristics and properties that describes a field. The field template
definition includes a field name, a data type, a setting for the field's Format property, and other field
properties.
1. On the Home tab, in the Views group, click View, and then click Datasheet View.
2. On the Datasheet tab, in the Fields & Columns group, click New Field.
3. Select one or more fields in the Field Templates pane, and then drag them to the table where you want
to insert the new column.
If your database already contains tables, you can add a field from one of those tables to your new
table by using the Field List pane. The Field List pane lists all the other tables in your database, grouped
into two categories:Fields available in related tables and Fields available in other tables. If the table
you are adding a field to is inrelationships with other tables, the related tables' fields are listed first in
the Field List pane.
2. In the Open dialog box, select and open the database that you want to work with.
4. On the Datasheet tab, in the Fields & Columns group, click Add Existing Fields.
5. Click the plus sign (+) next to a table in the Field List pane to display the list of fields in that table.
6. Select the field that you want, and drag it to the table where you want to insert the new column.
After you have completed the wizard, the field appears in the table in Datasheet view.
NOTE When you add a field from an unrelated table and then complete the Lookup Wizard, a new one-to-
many relationship is automatically created between the table in the Field List pane and the table that you
have open.
Find links to more information about the Lookup Wizard in the See Also section.
After you create a field, you can set field properties to control its appearance and behavior.
You can rename a field, change its data type, change its Format property, and change some of a field's other
properties while you work in Datasheet view.
Rename a field
When you add a field by entering data in Datasheet view, Access automatically assigns a generic name to
the field. Access assigns the name Field1 to the first new field, Field2 to the second new field, and so on. By
default, a field's name is used as its label wherever the field is displayed, such as a column heading on a
datasheet. Renaming fields so that they have more descriptive names helps make them easier to use when
you view or edit records.
1. Right-click the heading of the field that you want to rename (for example, Field1).
When you create a field by entering data in Datasheet view, Access examines that data to determine
the appropriate data type for the field. For example, if you enter 1/1/2006, Access recognizes that data as a
date and sets the data type for the field to Date/Time. If Access can't definitively determine the data type,
the data type is set to Text by default.
There may be cases where you want to manually change a field's data type. For example, suppose you
have room numbers that resemble dates, such as 10/2001.
If you enter 10/2001 into a new field in Datasheet view, the automatic data type detection feature
selects the Date/Time data type for the field. Because room numbers are labels, and not dates, they should
use the Text data type. Use the following procedure to change a field's data type.
2. In the Data Type list, in the Data Type & Formatting group, select the data type that you want.
In addition to determining the data type of a new field, Access may also set the Format property for
the field, depending on what you enter. For example, if you enter 10:50 a.m., Access sets the data type to
Date/Time and the Format property to Medium Time. To manually change a field's Format property, do the
following:
2. In the Format list, in the Data Type & Formatting group, enter the format that you want.
NOTE The Format list may be unavailable for some fields (for example, Text), depending on the data type
of the field.
1. In Datasheet view, click the field for which you want to set the property.
2. On the Datasheet tab, in the Data Type & Formatting group, select the properties that you want.
You can set any field property while you work with a table in Design view. In Design view, you set a
field's data type in the table design grid, and you set other properties in the Field Properties pane.
2. In the Data Type column, choose a data type from the list.
NOTE The data type of the field determines the properties that you can set.
2. In the Field Properties pane, enter the settings that you want for each property, or press F6 and then
use the arrow keys to select a property.
3. To provide more space for entering or editing a property setting in the property box, press SHIFT+F2 to
display the Zoom box.
TIP If you are entering an input mask or validation expression and would like help in building it, click
next to the property box to display the appropriate builder.
Find links to more information about data types and field properties in the See Also section.
Save a table
After you create or modify a table, you should save its design. When you save a table for the first time,
give it a name that describes the data that it contains. You can use up to 64 alphanumeric characters,
including spaces. For example, you might name a table Customers, Parts Inventory, or Products.
TIP You should decide on a naming convention for the objects in your database, and use it
consistently.
1. Click the Microsoft Office Button , and then click Save, or press CTRL+S .
2. If you are saving the table for the first time, type a name for the table, and then click OK.
After you have created a table for each subject in your database, you must provide Office Access 2007
with the means by which to bring that information back together again when needed. You do this by
placing common fields in tables that are related, and by defining table relationships between your
tables. You can then create queries, forms, and reports that display information from several tables at
once.
This article provides step-by-step procedures for creating, editing and deleting a table relationship.
You will learn how to enforce referential integrity to prevent the creation of orphan records, how to
set the join type to determine which records from each side of a relationships are included in a query
result, and how to set the cascade options to keep references synchronized.
For more information about table relationships, see the article Guide to table relationships.
In this article
Create a table relationship
Create a table relationship by using the Relationships document tab
Create a table relationship by using the Field List pane
Edit a table relationship
Enforce referential integrity
Delete a table relationship
Create a table relationship
You can create a table relationship in the Relationships window, or by dragging a field on to a
datasheet from theField List pane. When you create a relationship between tables, the common fields
are not required to have the same names, although it is often the case that they do. Rather, the
common fields must have the same data type. If the primary key field is an AutoNumber field,
however, the foreign key field can also be a Number field if theFieldSize property of both fields is the
same. For example, you can match an AutoNumber field and a Number field if the FieldSize property
of both fields is Long Integer. When both common fields are Number fields, they must have the
same FieldSize property setting.
4. If you have not yet defined any relationships, the Show Table dialog box automatically appears. If it
does not appear, on the Design tab, in the Relationships group, click Show Table.
The Show Table dialog box displays all of the tables and queries in the database. To see only tables,
click Tables. To see only queries, click Queries. To see both, click Both.
5. Select one or more tables or queries and then click Add. After you have finished adding tables and
queries to the Relationships document tab, click Close.
6. Drag a field (typically the primary key) from one table to the common field (the foreign key) in the
other table. To drag multiple fields, press the CTRL key, click each field, and then drag them.
7. Verify that the field names shown are the common fields for the relationship. If a field name is
incorrect, click on the field name and select the appropriate field from the list.
To enforce referential integrity for this relationship, select the Enforce Referential Integrity check
box. For more information about referential integrity, see the section Enforce Referential Integrity
Access draws a relationship line between the two tables. If you selected the Enforce Referential
Integrity check box, the line appears thicker at each end. In addition, again only if you selected
the Enforce Referential Integrity check box, the number 1 appears over the thick portion on one
side of the relationship line, and the infinity symbol (∞) appears over the thick portion on the on the
other side of the line, as shown in the following figure.
NOTES
To create a one-to-one relationship Both of the common fields (typically the primary key and
foreign key fields) must have a unique index. This means that the Indexed property for these fields
should be set to Yes (No Duplicates). If both fields have a unique index, Access creates a one-to-one
relationship.
To create a one-to-many relationship The field on the one side (typically the primary key) of the
relationship must have a unique index. This means that the Indexed property for this field should be
set to Yes (No Duplicates). The field on the many side should not have a unique index. It can have an
index, but it must allow duplicates. This means that the Indexed property for this field should be set to
either No or Yes (Duplicates OK). When one field has a unique index, and the other does not, Access
creates a one-to-many relationship.
In Office Access 2007, you can add a field to an existing table that is open in Datasheet view by
dragging it from the Field List pane. The Field List pane shows fields available in related tables and
also fields available in other tables in the database. When you drag a field from an "other" (unrelated)
table and then complete the Lookup Wizard, a new one-to-many relationship is automatically created
between the table in the Field List pane and the table to which you dragged the field. This
relationship, created by Access, does not enforce referential integrity by default. To enforce
referential integrity, you must edit the relationship. See the section Edit a table relationship for more
information.
TTLM Development Manual Date: 05-2011 Page 42 of
54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
Open a table in Datasheet view
1. Click the Microsoft Office Button , and then click Open.
2. In the Open dialog box, select and open the database.
3. In the Navigation Pane, right-click the table to which you want to add the field and create the
relationship, and then click Datasheet View on the shortcut menu.
Open the Field List pane
On the Datasheet tab, in the Fields & Columns group, click Add Existing Fields.
In the Field List pane, when you click the plus sign (+) next to a table name, you see a list of all the
fields available in that table. To add a field to your table, drag the field that you want from the Field
List pane to the table in Datasheet view.
Add a field and create a relationship from the Field List pane
1. On the Datasheet tab, in the Fields & Columns group, click Add Existing Fields.
2. Under Fields available in other tables, click the plus sign (+) next to a table name to display the list
of fields in that table.
3. Drag the field that you want from the Field List pane to the table that is open in Datasheet view.
4. When the insertion line appears, drop the field into position.
When you drag a field from an "other" (unrelated) table and then complete the Lookup Wizard, a new
one-to-many relationship is automatically created between the table in the Field List and the table to
which you dragged the field. This relationship, created by Access, does not enforce referential
integrity by default. To enforce referential integrity, you must edit the relationship. See the
section Edit a table relationship for more information.
You change a table relationship by selecting it in the Relationships document tab and then editing it.
1. Carefully position the cursor so that it points to the relationship line, and then click the line to select
it.
If you have not yet defined any relationships and this is the first time you are opening the
Relationships document tab, the Show Table dialog box appears. If the dialog box appears,
click Close.
All tables with relationships are displayed, showing relationship lines. Note that hidden tables (tables
for which theHidden check box in the table's Properties dialog box is selected) and their
relationships will not be shown unless Show Hidden Objects is selected in the Navigation
Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation
Pane.
The Edit Relationships dialog box allows you to change a table relationship. Specifically, you can
change the tables or queries on either side of the relationship, or the fields on either side. You can also
set the join type, or enforce referential integrity and choose a cascade option. For more information
about the join type and how to set it, see the section Set the join type. For more information about
how to enforce referential integrity and choose a cascade option, see the section Enforce referential
integrity.
When you define a table relationship, the facts about the relationship inform your query designs. For
example, if you define a relationship between two tables, and you then create a query that employs
the two tables, Access automatically selects the default matching fields based upon the fields specified
in the relationship. You can override these initial default values in your query, but the values supplied
by the relationship will often prove to be the correct ones. Because matching and bringing together
data from more than one table is something you will do frequently in all but the most simple
databases, setting defaults by creating relationships can be time saving and beneficial.
One of the values you can specify for each relationship is the join type. The join type tells Access
which records to include in a query result. For example, consider again a query that joins the
Customers table and the Orders table on the common fields that represents the Customer ID. Using
the default join type (called an inner join), the query returns only the Customer rows and the Order
rows where the common fields (also called the joined fields) are equal.
However, suppose you want to include all Customers — even those who have not yet placed any
orders. To accomplish this, you have to change the join type from an inner join to what is known as a
left outer join. A left outer join returns all of the rows in the table on the left side of the relationship
and only those that match in the table on the right. A right outer join returns all of the rows on the
right and only those that match on the left.
NOTE In this case, "left" and "right" refer to the position of the tables in the Edit
Relationships dialog box, not the Relationships document tab.
You should think about the result you will most often want from a query that joins the tables in this
relationship, and then set the join type accordingly.
The following table (using the Customers and Orders tables) shows the three choices that are
displayed in the Join Properties dialog box, the type of join they use, and whether all rows or
matching rows are returned for each table.
When you choose option 2 or option 3, an arrow is shown on the relationship line. This arrow points
to the side of the relationship that shows only matching rows.
If you have not yet defined any relationships and this is the first time you are opening the
Relationships document tab, the Show Table dialog box appears. If the dialog box appears,
click Close.
All tables that have relationships are displayed, showing relationship lines. Note that hidden tables
(tables for which the Hidden check box in the table's Properties dialog box is selected) and their
relationships will not be shown unless Show Hidden Objects is selected in the Navigation
Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation
Pane.
5. Click the relationship line for the relationship that you want to change. The relationship line appears
thicker when it is selected.
9. Make any additional changes to the relationship, and then click OK.
Enforce referential integrity
The purpose of referential integrity is to to prevent orphan records and to keep references
synchronized so that you don't have any records that reference other records that no longer exist. You
enforce referential integrity by enabling it for a table relationship. Once enforced, Access rejects any
operation that would violate referential integrity for that table relationship. This means that Access
will reject both updates that change the target of a reference and deletions that remove the target of a
reference. To have Access propagate referential updates and deletions so that all related rows are
changed accordingly, see the Set the cascade options section.
All tables with relationships are displayed, showing relationship lines. Note that hidden tables (tables
for which theHidden check box in the table's Properties dialog box is selected) and their
relationships will not be shown unless Show Hidden Objects is selected in the Navigation
Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation
Pane.
5. Click the relationship line for the relationship that you want to change. The relationship line appears
thicker when it is selected.
6. Double-click the relationship line. -or-
After you have enforced referential integrity, the following rules apply:
You cannot enter a value in the foreign key field of a related table if that value doesn't exist in the
primary key field of the primary table — doing so creates orphan records.
You cannot delete a record from a primary table if matching records exist in a related table. For
example, you cannot delete an employee record from the Employees table if there are orders assigned
to that employee in the Orders table. You can, however, choose to delete a primary record and all
related records in one operation by selecting the Cascade Delete Related Records check box.
You cannot change a primary key value in the primary table if doing so would create orphan records.
For example, you cannot change an order number in the Orders table if there are line items assigned to
that order in the Order Details table. You can, however, choose to update a primary record and all
related records in one operation by selecting the Cascade Update Related Fields check box.
If you have difficulty enabling referential integrity, note that the following conditions are required to
enforce referential integrity:
The common field from the primary table must be a primary key or have a unique index.
The common fields must have the same data type. The one exception is that an AutoNumber field can
be related to a Number field that has a FieldSize property setting of Long Integer.
Both tables exist in the same Access database. Referential integrity cannot be enforced on linked
tables. However, if the source tables are in Access format, you can open the database in which they are
stored and enable referential integrity in that database.
You might encounter a situation where you have a valid need to change the value on the "one" side of
a relationship. In such a case, you need Access to automatically update all of the affected rows as part
of a single operation. That way the update is completed in full so that your database is not left in an
inconsistent state — with some rows updated and some not. Access helps you avoid this problem by
supporting the Cascade Update Related Fields option. When you enforce referential integrity and
choose the Cascade Update Related Fields option, and you then update a primary key, Access
automatically updates all fields that reference the primary key.
You might also need to delete a row and all related records — for instance, a Shipper record and all
related orders for that shipper. For this reason, Access supports the Cascade Delete Related Records
option. When you enforce referential integrity and select the Cascade Delete Related Records check
box, Access automatically deletes all records that reference the primary key when you delete the
record that contains the primary key.
If you have not yet defined any relationships and this is the first time you are opening the
Relationships document tab, the Show Table dialog box appears. If the dialog box appears,
click Close.
TTLM Development Manual Date: 05-2011 Page 51 of
54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
4. On the Design tab, in the Relationships group, click All Relationships.
All tables that have relationships are displayed, showing relationship lines. Note that hidden tables
(tables for which the Hidden check box in the table's Properties dialog box is selected) and their
relationships will not be shown unless Show Hidden Objects is selected in the Navigation
Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation
Pane.
5. Click the relationship line for the relationship that you want to change. The relationship line appears
thicker when it is selected.
6. Double-click the relationship line. -or-
NOTE If the primary key is an AutoNumber field, selecting the Cascade Update Related
Fields check box will have no effect, because you cannot change the value in an AutoNumber field.
To remove a table relationship, you must delete the relationship line in the Relationships document
tab. Carefully position the cursor so that it points to the relationship line, and then click the line. The
relationship line appears thicker when it is selected. With the relationship line selected, press
DELETE. Note that when you remove a relationship, you also remove referential integrity support for
that relationship, if it is enabled. As a result, Access will no longer automatically prevent the creation
of orphan records on the "many" side of a relationship.
If you have not yet defined any relationships and this is the first time you are opening the
Relationships document tab, the Show Table dialog box appears. If the dialog box appears,
click Close.
All tables that have relationships are displayed, showing relationship lines. Note that hidden tables
(tables for which the Hidden check box in the table's Properties dialog box is selected) and their
relationships will not be shown unless Show Hidden Objects is selected in the Navigation
Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation
Pane.
5. Click the relationship line for the relationship that you want to delete. The relationship line appears
thicker when it is selected.
6. Press the DELETE key. -or-
7. Access might display the message Are you sure you want to permanently delete the selected
relationship from your database?. If this confirmation message appears, click Yes.
NOTE If either of the tables employed in the table relationship are in use — perhaps by another
person or process, or in an open database object, such as a form — you will not be able to delete the
relationship. You must close any open objects that employ these tables before you try to remove the
relationship.
1. Create a new table in a new database 7. Set field properties in Datasheet view
2. Create a new table in an existing database 7.1. Open a table in Datasheet view
3. Create a new table by using a table 7.2. Rename a field
template 7.3. Change a field's data type
4. Create a new table by importing/linking to 7.4. Change a field's format
external data 7.5. Set other field properties
4.1. Set a table's primary key 8. Set field properties in Design view
4.2. Set or change the primary key 8.1. Open a table in Design view
4.3. Remove the primary key 8.2. Set other field properties
5. Set a table's properties 9. Save a table
6. Table field 10. Create to table
6.1. Add a field to a table 10.1. Create relationship
6.2. Add a field by entering data 10.1.1. One to one relationship
6.3. Add a field by using a field 10.1.2. One to Many relationship
template 10.1.3. Many to Many
6.4. Add a field from an existing table relationship
6.5. Set field properties 10.2. Edit relationship
10.3. Delete relationship
7.1 7.2 7.3 7.4 7.5 8.1 8.2 9 10.1.1 10.1.2 10.1.3 10.2 10.3