Sie sind auf Seite 1von 54

Ethiopian TVET-System

INFORMATION TECHNOLOGY SUPPORT SERVICE

Level II

LEARNING GUIDE # 1

Unit of Competence: Operate Database Application


Module Title: Operating Database Application
LG Code: ICT ITS2 LO1 01
TTLM Code: ICT ITS2 TTLM 0511
LO 2: Create database Tables
Introduction 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

 Open and design database application incorporating basic design principles


 Create database object according to database usage, as well as user requirements
 Modify database object as required
 Add and modify data in a table according to information requirements
 Add, modify and delete records as required & Save and compile database objects

Learning Activities
1. Read the specific objectives of this Learning Guide.

2. Read the information written in the “Information Sheets 1”.

3. Accomplish the “Self-check1”.

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

Row IDNumber LName FName Mname Gender Bday Address


MOE-0001 Mekonen Abate Arega Male 11-05-1978 Addis
Record
MOE-0002 Mengestu Abera Negera Male 11-05-1978 Addis
File
MOE-0003 Kalid Mohamed Abas Male 11-05-1978 Adama
MOE-0004 Bekele Abebe Teferan Male 11-05-1978 Gonder
MOE-0005 Niguse Reta Yemane Female 11-05-1978 Jijiga

Fieldnames
 “MOE-0001” is the data for IDNumber field. And IDNumber is a fieldname for that data.

1 Record MOE-0001 Cuevas Noel Pancho Male 11-05-1978 Aratkilo

 Row gives information.


 It tells that NoelPancho Cuevas is a Male whose birthday is on 11-05-1978 and who lives in
Aratkilo.

Data types in Microsoft Access

 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.

Object Linking and Embedding is a proprietary technology developed by Microsoft that


allows embedding and linking to documents and other objects.

 Number: for numerical data used in mathematical calculations.


 Within the number type we are able to specify the size property of the
field.
 The types Byte, Integer and Long Integer allow the storage of numbers
without decimals; the types Single, Double and Decimal allow decimals;
the type Replication ID is used for autonumerical codes in replication
databases.
 The exact number type is configured using the Field Size property.
 Quantity, size, length, weight, speed, Scores, percentages,
 Date/Time: for the introduction of date and time from the year 100 to 9999.
 The Date/Time data type is used to store date values, time values, or combined date
and time values.
 Birth date, order date, expiration date, creation date, subscription date
 In the background Access always stores the date and time you enter like a number.
 Currency: For monetary/economic values and numerical data used in mathematical
calculations in which the data involved contains between one and four decimals.
 The accuracy is up to 15 digits to the left of the decimal separator and up to 4 digits
to the right of the same.
 The currency data type is especially suited for calculations that involve currencies
because it prevents rounding errors with very small fractions that are common to
floating point Number types like Double.
 Price
 Autonumber: a unique sequential number (increasing one by one), or a number that
Access assigns every time it adds a new record to a table.
 AutoNumber is a data type that is used to let Access generate unique numeric values
for you.
 Autonumber fields cannot be updated.
 The AutoNumber data type is used on primary key fields, because primary keys
must be unique and it is good practice to leave the job of generating new keys to the
database.
 Yes/No: Yes and No values, and fields that contain one of two values (Yes/No, True/False
or Activated/Deactivated).
 The Yes/No data type is called a Boolean data type in most databases.
 The Yes/No data type is pretty simple.
 It just lets you chose between Yes and No. This data type is used for yes/no
questions.
 Yes/No situations like 'wants to receive newsletter or doesn't want to receive
newsletter', 'product is on offer or product is not on offer', etc.
 OLE Object: an object such as a Microsoft Excel spreadsheet, a Microsoft Word document,
graphics, images, sounds, or other binaries.
 Used to embed or link to documents from other programs like Excel and Word.
 Hyperlink: text or a combination of text and numbers stored as text and used as a
hyperlink address.
 The Hyperlink data type is a text field, but a bit consider
 This field is used to store links.
 In the data sheet, the stuff you type into a Hyperlink field is automatically pretended
with http:// by Access and it is displayed as a clickable link.
 A Hyperlink is a text or graph that you click to go to a file, a location in a file, a web
page on the Internet, or a web page on an intranet.
 Attachment: Used to store files in an Access database.
 The attachment data type lets you store one or more files per record.
 The Attachment data type is used to store one or more files in a database field.
 If you set a field to the Attachment data type a small paperclip will display in the
Access data sheet.
 Double clicking the paperclip will open up a window that allows you to add one or
more files from your hard drive.
 Lookup wizard…: A lookup wizard field lets the user choose from a predefined set of
options, like a "male" or "female" selection or a "country" selection.
Field properties

 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 Text data type

 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.

Properties for the Text field

Property Explanation

The maximum number of characters you can enter. The largest maximum you can set
Field Size
is 255.

Format Rules for the display of this field in the datasheet

Input mask In input mask is a pattern that all data entered in this field must adhere to

When a caption text is entered, it is displayed as a field label in forms. If nothing is


Caption
filled out, the filed name is used for this purpose.

The default value is inserted by Access automatically when no other value is


Default value
supplied for the field.

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 Memo data type

 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.

The Number data type

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

Byte A Byte field allows whole numbers from 0 to 255. -

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

Replication A replication ID is a long alphanumeric string that is used in database


-
ID replication.

The most common Field Size values are probably Long Integer and Double.

The Date/Time data type

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.

Date picker widget for easy date selection

The Currency data type

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.

The AutoNumber data type

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

Yes/No fields appear as a checkbox in the data sheet.

Tables may be created by either:

 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)

 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.

Third Normal Form (3NF)

 Third normal form (3NF) goes one large step further:


 Meet all the requirements of the second normal form.
 Remove columns that are not dependent upon the primary key.

Boyce-Codd Normal Form (BCNF or 3.5NF)

 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.

Fourth Normal Form (4NF)

 Finally, fourth normal form (4NF) has one additional requirement:


 Meet all the requirements of the third normal form.
 A relation is in 4NF if it has no multi-valued dependencies.
 Remember, these normalization guidelines are cumulative. For a database to be in 2NF, it must
first fulfill all the criteria of a 1NF database.

Normalizing an Example Table

 These steps demonstrate the process of normalizing a fictitious student table.


1. Unnormalized table:

Student# Advisor Adv-Room Class1 Class2 Class3


1022 Jones 412 101-07 143-01 159-02
4123 Smith 216 201-01 211-02 214-01

2. First Normal Form: No Repeating Groups


 Tables should have only two dimensions. Since one student has several classes, these
classes should be listed in a separate table.
 Fields Class1, Class2, and Class3 in the above records are indications of design trouble.
 Spreadsheets often use the third dimension, but tables should not.
 Another way to look at this problem is with a one-to-many relationship, do not put the
one side and the many side in the same table.
 Instead, create another table in first normal form by eliminating the repeating group
(Class#), as shown below:

Student# Advisor Adv-Room Class#

1022 Jones 412 101-07


1022 Jones 412 143-01
1022 Jones 412 159-02
4123 Smith 216 201-01
4123 Smith 216 211-02
4123 Smith 216 214-01
3. Second Normal Form: Eliminate Redundant Data
 Note the multiple Class# values for each Student# value in the above table. Class# is not
functionally dependent on Student# (primary key), so this relationship is not in second
normal form.
 The following two tables demonstrate second normal form:
Students:

Student# Advisor Adv-Room


1022 Jones 412
4123 Smith 216
Registration:

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:

Name Room Dept


Jones 412 42

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

Types of Database Relationships

 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

 Keeping data separated in related tables produces the following benefits


 Consistency: because each time of data is recorded only once in one table, there is less
opportunity for ambiguity or inconsistency.
 Efficiency: recording data in only one place means you use less disk space. Moreover,
smaller tables tend to provide data more quickly than larger tables.
 Comprehensibility: the design of a database is easier to understand if the subject are
properly separated in to tables.

ER Diagrams (Entity Relationship Diagrams)

 An Entity Relationship Diagram (ERD) is a visual representation of different data using


conventions that describe how these data are related to each other.

 For example, the elements writer, novel, and consumer may be described using ER diagrams
this way:

ER diagram with basic objects

 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:

ER diagram example with entity having attributes

In the diagram, the information inside the oval shapes is attributes of a particular entity.

1.1.1 ER Diagram Symbols and Notations

Elements in ER diagrams

 There are three basic elements in an ER Diagram:

1. Entity 3. Relationship

2. Attribute

 There are more elements which are based on the main elements.

 Weak entity  Weak relationship and

 Multivalve attribute  Recursive relationship.

 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

 A weak entity is an entity that depends on the existence of another 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.

Weak Entity Example in ER diagrams

Attribute

 An attribute is a property, trait, or characteristic of an entity, relationship, or another 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.

 Meanwhile, attributes can also have their own specific attributes.

 For example, the attribute “customer address” can have the attributes number, street, city, and state.

 These are called composite attributes.

 Note that some top level ER diagrams do not show attributes for the sake of simplicity.

 In those that do, however, attributes are represented by oval shapes.

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.

Example of a multivalued attribute

Derived Attribute

 An attribute based on another attribute.

 This is found rarely in ER diagrams.

 For example for a circle the area can be derived from the radius.

Derived Attribute in ER diagrams

Relationship

 A relationship describes how entities interact.

 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.

Using Relationships in Entity Relationship Diagrams

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.

Example of a recursive relationship in ER diagrams


TTLM Development Manual Date: 05-2011 Page 20 of 54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
Cardinality and Ordinality

 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.

 The relationship in this case follows a “one to many” model.

 There are number of notations used to present cardinality in ER diagrams.

 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.

Cardinality in ER diagrams using UML notation

1.1.2 ER Diagram Templates

 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.

 For more templates check out ER diagram templates article.

ER Diagram Template of exam database (Click on the image to use as template )

TTLM Development Manual Date: 05-2011 Page 21 of 54


3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
 A basic ER diagram template for a quick start

Basic ER Diagram template (Click to use as template )

1.1.3 Benefits of ER diagrams

 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.

TTLM Development Manual Date: 05-2011 Page 22 of 54


3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

Self - Check 1 Creating Database Tables

Name: ______________________________________ Date: ________________________________________

Time started: _______________________________ Time finished: _______________________________

Directions: Answer all the questions listed below.

1. Metadata is also known as? ( 1 point )

2. Types of database tables relationship

3. A container or a worksheet-like container where the collection of data has been stored?

4. Every column in a table represents

5. A field in a table signifies a? (1 point)

6. The name of the field was called a? (1 point)

7. One row in a table signifies a?(1 point)

8. It is the primary and unique identification of a record? (1 points)

9. What are the two ways of creating a Table? (2 points)

10. The different kinds of Ms Access2007 data types

11. That allows you to describe the connections between different database tables in powerful ways.

Note: Satisfactory rating – above 9 points Unsatisfactory - below 8 points Unsatisfactory


(You can ask you teacher for the copy of the correct answer)

TTLM Development Manual Date: 05-2011 Page 23 of 54


3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

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

TTLM Development Manual Date: 05-2011 Page 24 of 54


3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

Operation Sheet-1 Creating Database Tables

Create a new table in a new database

1. Click the Microsoft Office Button , and then click New.

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.

Create a new table in an existing database

1. Click the Microsoft Office Button , and then click Open.

2. In the Open dialog box, select the database that you want to open, and then click Open.

3. On the Create tab, in the Tables group, click Table.

A new table is inserted in the database and the table opens in Datasheet view.

Use a table template to create a table


In earlier versions of Access, you used the Table Wizard to quickly create a table from sample tables
and fields. In Office Access 2007, you use table templates and field templates instead.
A table template is an empty table that you can start using as-is, or modify to suit your needs. Office
Access 2007 comes with the following table templates, designed to be compatible with the Windows
SharePoint Services 3.0 lists of the same name:

 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.

TTLM Development Manual Date: 05-2011 Page 25 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
 Assets A table for managing business assets, which includes two currency fields so that you can track
asset depreciation.

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.

Create a new table by using a table template

1. Click the Microsoft Office Button , and then click Open.

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.

Import or link to create a table

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.

TTLM Development Manual Date: 05-2011 Page 26 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
When you link to data, you create a linked table in the current database that represents a live link to
the existing information that is stored elsewhere. When you change data in a linked table, you are changing
it in the source. Whenever data changes in the source, that change is shown in the linked table. You must be
able to connect to the data source whenever you use a linked table. You cannot change the design of a linked
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.

Create a new table by importing or linking to external data

1. Click the Microsoft Office Button , and then click Open.

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.

Use a SharePoint site to create a table

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.

1. Click the Microsoft Office Button , and then click Open.

TTLM Development Manual Date: 05-2011 Page 27 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
2. In the Open dialog box, select the database in which you want to create the new table, and then
click Open.

3. On the Create tab, in the Tables group, click SharePoint Lists.

4. Do one of the following:

Create a SharePoint list that is based on a template

1. Click either Contacts, Tasks, Issues, or 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).

 Create a new custom list

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).

TTLM Development Manual Date: 05-2011 Page 28 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
 Import the data from an existing list

1. Click Existing SharePoint List.

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.

 Link to an existing list

1. Click Existing SharePoint List.

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.

Set a table's primary key

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.

TTLM Development Manual Date: 05-2011 Page 29 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
Determine which fields to use as a primary key

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.

Set or change the primary key

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.

4. On the Design tab, in the Tools group, click Primary Key.

A key indicator appears to the left of the field or fields that you specify as the primary key.

TTLM Development Manual Date: 05-2011 Page 30 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
Remove the primary key
1. Select the table whose primary key you want to remove.

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.

4. On the Design tab, in the Tools group, click Primary Key.

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.

Set a table's properties


In addition to setting properties fields, you can also set properties that apply to an entire table or to entire
records.
1. Select the table whose properties you want to set.

2. On the Home tab, in the Views group, click View, and then click Design View.

3. On the Design tab, in the Show/Hide group, click Property Sheet.

The table property sheet is shown.

4. On the property sheet, click the General tab.


TTLM Development Manual Date: 05-2011 Page 31 of
54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
5. Click the box to the left of the property that you want to set, and then enter a setting for the property.

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.

6. To save your changes, press CTRL+S.

Add a field to a table


You store each piece of data that you want to track in a field. For example, in a contacts table you
create fields for Last Name, First Name, Telephone Number, and Address. In a products table you create
fields for Product Name, Product ID, and Price.
Before you create fields, try to separate data into its smallest useful parts. It is much easier to combine
data later than it is to pull it apart. For example, instead of a Full Name field, consider creating separate
fields for Last Name and First Name. Then, you can easily search or sort by First Name, Last Name, or both.
If you plan to report, sort, search, or calculate on an item of data, put that item in a field by itself. For more
information about designing a database and creating fields, see the links in the See Also section.
After you create a field, you can also set field properties to control its appearance and behavior.
What do you want to do?

 Add a field by entering data


 Add a field from an existing table
 Set field properties
Add a field by entering data
When you create a new table or open an existing table in Datasheet view, you can add a field to the
table by entering data in the Add New Field column of the datasheet.

TTLM Development Manual Date: 05-2011 Page 32 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
1. Enter data in the Add New Field column.
2. Create or open a table in Datasheet view.

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.

Use a descriptive name so that the field will be easier to identify.

3. Enter data in the new field.

Add a field by using a field template

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.

TTLM Development Manual Date: 05-2011 Page 33 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
Add a field from an existing table

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.

1. Click the Microsoft Office Button , and then click Open.

2. In the Open dialog box, select and open the database that you want to work with.

TTLM Development Manual Date: 05-2011 Page 34 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
3. In the Navigation Pane, double-click the table to which you want to add an existing field.

The table opens in Datasheet view.

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.

7. Follow the instructions in the Lookup Wizard.

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.

Set field properties

After you create a field, you can set field properties to control its appearance and behavior.

For example, by setting field properties, you can:

 Control the appearance of data in a field


 Help prevent incorrect data entry in a field
 Specify default values for a field
 Help speed up searching and sorting on a field

TTLM Development Manual Date: 05-2011 Page 35 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
You can set some of the available field properties while you work in Datasheet view. To have access to and
set the complete list of field properties; however, you must use Design view.

Set field properties in Datasheet view

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.

Open a table in Datasheet view


1. In the Navigation Pane, right-click the table that you want to open.

2. On the shortcut menu, click 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).

2. On the shortcut menu, click Rename Column.

3. Enter the new name in the field heading.

Field names can consist of up to 64 characters (letters or numbers), including spaces.

Change a field's data type

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.

TTLM Development Manual Date: 05-2011 Page 36 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
The data type of the field determines which other field properties you can set. For example, you can
set only theAppend Only property for a field that has the Hyperlink data type or the Memo data type.

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.

1. On the Ribbon, click the Datasheet tab .

2. In the Data Type list, in the Data Type & Formatting group, select the data type that you want.

Change a field's format

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:

1. On the Ribbon, click the Datasheet tab.

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.

Set other field properties

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.

TTLM Development Manual Date: 05-2011 Page 37 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

Set field properties in Design view

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.

Open a table in Design view


1. In the Navigation Pane, right-click the table.

2. On the shortcut menu, click Design view.

Change a field's data type


1. In the table design grid, locate the field for which you want to set the data type.

2. In the Data Type column, choose a data type from the list.

Set other field properties


1. In the table design grid, select the field for which you want to set properties. Access displays the
properties for this field in the Field Properties pane.

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.

4. To save your changes, press CTRL+S.

Find links to more information about data types and field properties in the See Also section.

TTLM Development Manual Date: 05-2011 Page 38 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

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.

TTLM Development Manual Date: 05-2011 Page 39 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

Operation Sheet-2 Creating Database Tables Relationship


Create, edit or delete a relationship

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.

Create a table relationship by using the Relationships document tab


1. Click the Microsoft Office Button , and then click Open.
2. In the Open dialog box, select and open the database.
3. On the Database Tools tab, in the Show/Hide group, click Relationships.

TTLM Development Manual Date: 05-2011 Page 40 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

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.

The Edit Relationships dialog box appears.

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

TTLM Development Manual Date: 05-2011 Page 41 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
8. Click Create.

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.

Create a table relationship by using the Field List pane

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.

The Field List pane appears.

TTLM Development Manual Date: 05-2011 Page 43 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
The Field List pane shows all of the other tables in your database, grouped into categories. When you
work with a table in Datasheet view, Access displays fields in either of two categories in the Field
List pane: Fields available in related tables and Fields available in other tables. The first category
lists all of the tables that have a relationship with the table with which you are currently working. The
second category lists all of the tables with which your table does not have a relationship.

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.

The Field List pane appears.

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.

The Lookup Wizard starts.

5. Follow the instructions to complete the Lookup Wizard.

The field appears in the table in Datasheet view.

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.

TTLM Development Manual Date: 05-2011 Page 44 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
Edit a table relationship

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.

The relationship line appears thicker when it is selected.

2. With the relationship line selected, double-click it. –or–

On the Design tab, in the Tools group, click Edit Relationships.

The Edit Relationships dialog box appears.

Open the Edit Relationships dialog box


1. Click the Microsoft Office Button , and then click Open.
2. In the Open dialog box, select and open the database.
3. On the Database Tools tab, in the Show/Hide group, click Relationships.

The Relationships document tab appears.

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.

4. On the Design tab, in the Relationships group, click All Relationships.

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.

TTLM Development Manual Date: 05-2011 Page 45 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
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-

On the Design tab, in the Tools group, click Edit Relationships.

The Edit Relationships dialog box appears.

7. Make your changes, and then click OK.

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.

Set the join type

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.

TTLM Development Manual Date: 05-2011 Page 46 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
A multiple table query combines information from more than one table by matching the values in
common fields. The operation that does the matching and combining is called a join. For instance,
suppose you want to display customer orders. You create a query that joins the Customers table and
the Orders table on the Customer ID field. The query result contains customer information and order
information for only those rows where a corresponding match was found.

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.

Set the join type


1. In the Edit Relationships dialog box, click Join Type.

The Join Properties dialog box appears.

2. Click your choice, and then click OK.

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.

CHOICE RELATIONAL LEFT RIGHT


JOIN TABLE TABLE
1. Only include rows where the joined fields from Inner join Matching Matching
both tables are equal. rows rows
2. Include ALL records from 'Customers' and only Left outer join All rows Matching
those records from 'Orders' where the joined fields rows
are equal.
TTLM Development Manual Date: 05-2011 Page 47 of
54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
3. Include ALL records from 'Orders' and only those Right outer join Matching All rows
records from 'Customers' where the joined fields are rows
equal.

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.

Make changes in the Join Properties dialog box


1. Click the Microsoft Office Button , and then click Open.
2. In the Open dialog box, select and open the database.
3. On the Database Tools tab, in the Show/Hide group, click Relationships.

The Relationships document tab appears.

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.

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.

TTLM Development Manual Date: 05-2011 Page 48 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
6. Double-click the relationship line. -or-

On the Design tab, in the Tools group, click Edit Relationships.

The Edit Relationships dialog box appears.

7. Click Join Type


8. In the Join Properties dialog box, click an option, and then click OK.

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.

Turn referential integrity on or off


1. Click the Microsoft Office Button , and then click Open.
2. In the Open dialog box, select and open the database.
3. On the Database Tools tab, in the Show/Hide group, click Relationships.

The Relationships document tab appears.

TTLM Development Manual Date: 05-2011 Page 49 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
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.

4. On the Design tab, in the Relationships group, click All Relationships.

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-

On the Design tab, in the Tools group, click Edit Relationships.

The Edit Relationships dialog box appears.

7. Check Enforce Referential Integrity.


8. Make any additional changes to the relationship, and then click OK.

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.

TTLM Development Manual Date: 05-2011 Page 50 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material
NOTES

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.

Set the cascade options

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.

Turn cascade update and/or cascade delete on or off


1. Click the Microsoft Office Button , and then click Open.
2. In the Open dialog box, select and open the database.
3. On the Database Tools tab, in the Show/Hide group, click Relationships.

The Relationships document tab appears.

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-

On the Design tab, in the Tools group, click Edit Relationships.

The Edit Relationships dialog box appears.

7. Select the Enforce Referential Integrity check box.


8. Select either the Cascade Update Related Fields or the Cascade Delete Related Records check box,
or select both.
9. Make any additional changes to the relationship, and then click OK.

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.

Delete a table relationship

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.

1. Click the Microsoft Office Button , and then click Open.


2. In the Open dialog box, select and open the database.
3. On the Database Tools tab, in the Show/Hide group, click Relationships.

TTLM Development Manual Date: 05-2011 Page 52 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

The Relationships document tab appears.

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.

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 delete. The relationship line appears
thicker when it is selected.
6. Press the DELETE key. -or-

Right-click and then click DELETE.

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.

TTLM Development Manual Date: 05-2011 Page 53 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID
Ethiopian TVET System
Training, Teaching and Learning Material

LAP Test Creating Database Table

Name: ______________________________________ Date: ________________________________________

Time started: _______________________________ Time finished: _______________________________

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

1 2 3 4 4.1 4.2 4.3 5 6.1 6.2 6.3 6.4 6.5

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

TTLM Development Manual Date: 05-2011 Page 54 of


54
3rd Revision Author: ADDIS ABABA TEGBARE-ID

Das könnte Ihnen auch gefallen