Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

Block 6

Unit- IV Basics of MS Access

4.1 Introduction
4.2 Objective
4.3 Creating tables
4.4 Creating reports
4.5 Creating queries
4.6 Working with forms
4.7 Entering records in the table
4.8 Working with relationships in MS Access
4.9 Using primary and secondary keys in table
4.10 Importing and exporting data from and to excel
4.11 Summary
4.12 Answers/Solutions
4.13 Further Reading

1
4.1 INTRODUCTION

Databases are very important part of computer applications. Majority of applications


used every day by different types of users are associated with database also. Database
can be defined as organized collection of logically related data. The information
stored in a database is subject oriented ie related to a particular subject. For example
weather forecasting database will store information about weather and a bank
database will store information about customer's accounts. Database is also called
integrated data storage, where the data of an organization is stored and maintained at
a single point. Before database approach can in to existence, traditional files were
used to store and access the information. But that was not efficient method to access
the required information due to distributed (data was stored in different files and
stored in different locations with respect to the concerned department) method of data
storage. Thus if, some one has to get some information, based upon scattered data
among multiple files, he or she had to identify required files first and then to access
them to collect chunks of required data to finally club them to make some useful
information.

Database is used as backend in software applications, where as the front end is some
application through which user interacts with the database (backend). For example,
the login windows are front end where we supply user id and password, and the
storage house of such authorized user id's and passwords are stored is a database. To
understand data base with real life example, Let us we consider tap in kitchen as front
end, thus the water tank on the terrace/roof can be considered as database ie backend
and here the subject of database is water, being subject oriented also. The data in the
database can be accessed more easily being available at the single point and there is
no need to update the data at multiple points if some change is required in a data
value, thus data redundancy (Unnecessary repetition of data) problem is also taken
care of. Redundancy leads to inconsistency which makes data erroneous. For example
if an employee is working in multiple departments in an organization, and his
residential address is changed, then all the departments should update his address in
his personal information record. By mistake if one of the departments has not
changed his record as per the new address, in that case address information is not
reliable for communication. Database is solutions to such kind of data related
problems.

2
How to start MS Access

Figure 1

3
4.2 OBJECTIVE
The objective of this unit is to enable the user to use database in efficient manner and
to make user well versed with different types of jobs , which can be done using data
base. In the end of the unit user will learn to

• Create tables
• Create reports
• Create queries
• Use forms
• Entering records in the table
• Working with relationships
• Using primary and secondary keys in table
• Importing and exporting data from and to excel

4.3 CREATING TABLES


The table is used to store data in MS Access. Table is a collection of rows and
columns, and the data is stored in a cell (intersection of a row and a column). MS
Access table is used for powerful relational database and reporting capabilities.
Relational database stores information in the form of tables. It uses matching values
from one table to relate data in another table. In a relational data base we store
specific type of data only once.

The steps to create a table are given below. Figures 2 to Figure 4 explain the
procedure to open a database.

I. Start Microsoft Access Instance


II. Create or Open a database by selecting file menu
III. Click on New or Open command.
IV. Select Tables from the list of objects
V. Choose one of the three ways to create a table

4
Figure 4

Figure 4

Figure 4
5
There are three ways to create table

Create table in Design View : Figure 5 to Figure 15 explains the creation of table in
design view.

I. Select create table in design view


II. Follow steps shown in figures 5 to figure 15

Figure 6

Figure 6

6
Figure 9

In the given below diagram click on the X on the right top to close

Figure 9

Figure 9

7
Figure 13

Figure 13

Figure 13

Figure 13

8
Figure 15

Figure 15

Second Method : Create Table Using Wizard

I. Select create table using wizard


II. Follow steps shown in figures 16 to figure 22

Figure 16 to Figure 22 explain the procedure to create a table using Wizard.

Figure 16
9
Figure 18

Figure 18

10
Figure 21

Figure 21

Figure 21 11
Figure 22

Third Method : Creating Table Entering Data

You can also create table directly. Double click on create table by entering data
option and you will get a table having ten fields by default, which can be further
increased by using right click of mouse on any field's head and choose insert column
option.

4.4 CREATING REPORTS


Reports are used to represent data in a printed format in a customized manner. One
can make changes in the appearance of report components to represent the
information in an effective manner. Reports are created by the help of one or more
tables and query in a database. The record source of a report is fields in the
underlying queries. Selected fields from table(s) or queries can be used as the record
source in a report. The design view of a report is used to store and represent the other
important components like title, date, page number and time etc.

Some controls (graphical objects) are used to make link between a report and its
record source. These graphical objects can be labels, text boxes or lines. Text boxes
are used to display the value of respective field from the table or query where as the
labels are used to show the name of the field.

Creating a report

There are two ways to create reports. First is by using design view and another is
using wizard. By using wizard one can create a standard report, which can be
customized in design view. A wizard asks you questions and creates a report
based on your answers

Customizing a report

Following components help to customize a report

12
Record source Change the tables and queries that a report is based on.

Sorting and grouping data You can sort data in ascending or descending order.
You can also group records on one or more fields, and display subtotals and grand
totals on a report.

Report window You can add or remove Maximize and Minimize buttons,
change the title bar text, and other Report window elements.

Sections You can add, remove, hide, or resize the header, footer, and details
sections of a report. You can also set section properties to control the appearance
and printing of a report.

Controls You can move, resize, or set the font properties of a control. You can
also add controls to display calculated values, totals, current date and time, and
other useful information on a report.

STEPS TO CREATE A REPORT

I. Start Microsoft Access Instance


II. Open a database by selecting file menu
III. Click on Open command.
IV. Select Reports from the list of objects
V. Select create report by using wizard
VI. Select table or query to make report from tables/queries Combo box
VII. Select the fields from Available Fields List box to Selected Fields List box
one by one using, command button or select all available fields by
clicking on command button.
VIII. Select grouping labels if required, say CompanyName
IX. Then select the sorting fields of record in the report , say
ContactFirstName
X. Select the Layout of the report
XI. Select the report Style
XII. Give a title to the report, say Customer's Information

The pictorial representatin of the procedure is shown through Figure 23 to Figure 34.

13

Figure 23
Figure 26

Figure 26

Figure 26

14
Figure 29

Figure 29

15

Figure 29
Figure 32

Figure 32

16
Figure 32
Figure 34

Figure 34

17
We can verify the details shown in the above report (Figure 34), with the table given
below (Figure 35)

Figure 35

4.5 CREATING QUERIES


Queries are used to view, edit and analyze data in different ways. Queries can also be
used as a data source (source of records) for other objects of MS Access like forms and
reports. Microsoft Access is having different types of queries.

SELECT QUERIES

The most common type of query is select query. It is used to retrieve data from single or
multiple tables. The retrieved records are displayed in a datasheet. The select query is
also used for aggregate functions like sum, count, average, and other types of totals. It
can also be used to group records.

PARAMETER QUERIES

Such queries are more interactive. At the time of execution, parameters will be asked
from the user to set criteria for retrieving particular records only as per the need.

We can design the query to get more than one value from the user. For example user can
be asked to supply to values of data and then display those records having date of joining
between these two dates.

18
Parametric queries are also useful when used with respect to forms or reports also. For
example, an interactive query can ask the user to supply the value of month to display the
report of that particular month only.

CROSSTAB QUERIES

Crosstab queries are used for easier analysis of data. Such queries are used to calculate
sum, average, count, and such kind of totals for data which is grouped by two information
patterns, one down the left side of the datasheet and another across the top.

ACTION QUERIES

An action query is like Data Manipulation Language or Data Definition Language.


Action query effect multiple records in a single operation. There are four types of action
queries.

• Delete Queries A delete query is used to delete a single or group of records


from one or multiple tables. For example, we can use a delete query to remove the
details of students who have not passed the examination to get admission in a
course. Delete query is used to delete the complete record and not to delete some
fields only.

To understand action query with an illustration, let’s consider a table named


tblResult having four fields like Name, Age, Rollno and Result.

Record No Name Age Rollno Result


1 Mr. Arun 25 15039 Pass
2 Mr. Ratul 40 12367 Fail
3 Ms. Mukta 23 12678 Pass
4 Ms. Monika 19 12489 Fail

If we use an action query to remove records of fail students then after the
execution of query, resultant table will be

Record No Name Age Rollno Result


1 Mr. Arun 25 15039 Pass
2 Ms. Mukta 23 12678 Pass

• Update Queries An update query is used to make changes to a group of records


in a single or multiple tables. For example, we can use update queries to increase
daily wages of employees who are working for last 5 years with the organization
by 5%. We can also use update query to edit data in the existing tables.
• Append Queries Append query is used to add records form one or more source
tables to the end of the target table. For example, some students have changed
their electives, so we can append the details of the new students in the

19
corresponding tables from the main database of students, instead of retyping the
same details again.
• Make-Table Queries By the help of make table query, we can create new
tables from other tables. There are situations when we want to gather data from
other single or multiple tables to make a single consolidated table, there we make
use of the make table query. Make table queries are also helpful to export data to
other MS Access objects like queries, forms and reports with the help of a table
created for such activities.

SQL QUERIES

Structure Query Language (SQL) queries are used to manage relational databases like
MS Access. The queries are created by the help of SQL statements. A query can be
created in the design view. Design view is a window which shows the design of MS
Access objects like tables, forms, queries, reports and macros etc. Design view helps the
use to create new database objects and also to modify the design of existing objects. Also,
when we create a query in design view, access constructs the SQL equivalent statements
automatically w.r.t such designed queries. Generally most of the properties in the
property sheet in query Design view have equivalent clauses and options which are
available in the SQL view also. SQL-View can also be used to create a customized SQL-
query. However, after changes, the query might not be displayed the way it was
previously in Design view.

Also, the design grid (grid used to design a query) is having limitations when we have to
design some specific SQL queries having sub-queries and relational algebra related
functionalities. Also there are situations when we want to communicate to an ODBC
database server instead of executing the queries through Microsoft Jet database engine to
process the data, where design grid is again having its limitations. Other situation where
the design grid is not the appropriate choice for the user is, the data definition language
(DDL) and union queries which are used to create and alter the objects in the database
and to combine the result of two or more select queries respectively.

For sub-queries we have to enter the SQL in the Field row or the Criteria row of the
query design grid. Sub query is a query which is embedded within a SQL query.

STEPS TO CREATE A QUERY

I.Start Microsoft Access Instance


II.Open a database by selecting file menu
III.Click on Open command
IV. Select a Database (in this case we have selected database IGNOU)
V. Click on the query object ( It will show two ways to create a query)
a. Create query in design view
b. Create query by using wizard
VI. It is good to create a query using wizard and then to customize in design view if
required.

20
VII. Select create query by using wizard
VIII. Select table or query to make query from tables/queries Combo box
IX. Select the fields from Available Fields List box to Selected Fields List box one
by one using, command button or select all available fields by clicking on
command button.
X. Select the type of query you want i.e. detailed or summary
XI. Give title to query
XII. Select one of the given below options
a. Open the query to view information
b. Modify the query design

The procedure is explained pictorially through Figure 36 to Figure 47.

Figure 38 Figure 38

Figure 38

21
Figure 43

Figure 43
Figure 43

Figure 43 Figure 43

22
Figure 46

Figure 46

Figure 46

23
In the table given below the ID field is not shown in the query result.

Figure 47

Check your progress 1

Question 1: Fill in the blanks.

1. The ______is used to store data in MS Access.


2. ______is a collection of rows and columns
3. Data is stored in a ______which is intersection of a row and a column.
4. MS Access table is used for powerful ______database and reporting capabilities.
5. Relational database stores ______in the form of tables.
6. ______ are used to represent data in a printed format in a customized manner.
7. One can make changes in the appearance of report components to represent the
information in an ______ manner.
8. Reports are created by the help of one or more ______ and ______ in a database.
9. The record source of a report is fields in the underlying ______.
10. Selected fields from table(s) or queries can be used as the record source in a
______.

Question 2: What are cross tab queries?

24
4.6 WORKING WITH FORMS
Form is a data base object which is used as front end application (Application through
which user interacts with database).

A form is a type of a database object that is primarily used to enter or display data in a
database. You can also use a form as a switchboard that opens other forms and reports in
the database, or as a custom dialog box that accepts user input and carries out an action
based on the input.

Generally forms are bound to one or more tables and queries in a database.

Most forms are bound to one or more tables and queries in the database. A form may or
may not contain all the field s of the tables or queries with which it is associated. The
record source of a form refers to the fields in the tables and queries with which the form
are bound.

A bound form stores or retrieves data form the associated record source. The form also
contains other components like title, date, time, and page number, which is stored in the
form’s design like

• Graphic elements, such as lines and rectangles, are stored in the form's design.
• Data comes from the fields in the underlying record source.
• A calculation comes from an expression, which is stored in the form's design.
• Descriptive text is stored in the form's design.

Graphical objects are used to make a link between form and record source. Such
graphical objects are called controls e.g. command button, text box, check box, scroll
bar etc. Text box is used as the most common type of control to display and enter
data. Labels are used to display description text. Command buttons are used to invoke
some action associated with some procedure or data element.

CREATING A FORM

We can create a form either in design view or by using form wizard. It is more
convenient to create a form using wizard and then customize it as per the specific needs
in the design view. A form can be bound to a table or query.

You can customize a form in Design view in the following ways:

Record source Change the tables and queries that a form is based on.

25
Controlling and assisting the user You can set form properties to allow or prevent users
from adding, deleting, or editing records displayed in a form. You can also add custom
Help to a form to assist your users with using the form.

Form window You can add or remove Maximize and Minimize buttons, short cut
menus, and other Form window elements.

Sections You can add, remove, hide, or resize the header, footer, and details sections of a
form. You can also set section properties to control the appearance and printing of a
form.

Controls You can move, resize, or set the font properties of a control. You can also add
controls to display calculated values, totals, current date and time, and other useful
information on a form.

26
STEPS TO CREATE A FORM

I. Start Microsoft Access Instance


II. Open a database by selecting file menu
III. Click on Open command.
IV. Select Form from the list of objects
V. Select create form by using wizard
VI. Select table or query to make form from tables/queries Combo box
VII. Select the fields from Available Fields List box to Selected Fields List box one
by one using, command button or select all available fields by clicking on
command button.
VIII. Select grouping labels if required, say CompanyName
IX. Then select the sorting fields of record in the report , say ContactFirstName
X. Select the Layout of the report
XI. Select the report Style
XII. Give a title to the report, say Customer's Information

The procedure is represented pictorially by the help of Figure 48 to Figure 59.

Figure 49

Figure 49

27
Figure 52

Figure 52

Figure 52
28
Figure 55

Figure 55

Figure 55

29
Figure 58

Figure 58

Figure 58
30
Figure 60

The newly created form is shown by the figure shown below.

Figure 60

If we go back to table object and click on the table tblStudent, we can view the newly
added record through form, available in the table, shown in the Figure 61.

Figure 61
31
Figure 62 shows the procedure to make changes in the form by opening the form in
design view. Figure 62 shows the effect of changes in the form design.
To open a form in design view, select the form and click on the design view button
shown by red circle in the Figure 62. We have added form title, date and time on the
form.

Figure 62

32
Figure 63

33
4.7 ENTERING RECORDS IN THE TABLE
There are multiple ways to enter records in a table. One can enter records directly in
the table by opening the table using following steps

• Select table object

Figure 64

• Open the table from the available list of tables by


o Right click on the table name and click on open command from the pop up
menu as shown in Figure 65 Or
o Double click on the table name

Figure 65

34
• Click on the first field of the record pointed by new record pointer (*), Figure 66

Figure 61

We can also enter records in the table, using forms.

4.8 WORKING WITH RELATIONSHIPS IN MS


ACCESS
Relationship is an association between two tables on the basis of a common filed
(attribute)There are different types of relationships

One to One
Relationship between Rollno and student i.e. one student has only one Rollno. In a
one-to-one relationship, each record in Table A can have only one matching record in
Table B, and each record in Table B can have only one matching record in Table A.
This type of relationship is not common, because most information related in this way
would be in one table. You might use a one-to-one relationship to divide a table with
many fields, to isolate part of a table for security reasons, or to store information that
applies only to a subset of the main table. For example, you might want to create a
table to track employees participating in a fundraising soccer game. Each soccer
player in the Soccer Players table has one matching record in the Employees table.

One to Many
Relationship between Manager and employees i.e. one manager can have many
employees in his department. Also, a one-to-many relationship is the most common
type of relationship. In a one-to-many relationship, a record in Table A can have
many matching records in Table B, but a record in Table B has only one matching
record in Table A.

35
Many to Many

Relationship between subjects and students i.e. many subjects can be chosen by many
students. In a many-to-many relationship, a record in Table A can have many
matching records in Table B, and a record in Table B can have many matching
records in Table A. This type of relationship is only possible by defining a third table
(called a junction table) whose primary key consists of two fields— the foreign keys(
It is a primary key of another table. It is used to relate tables) from both Tables A and
B. A many-to-many relationship is really two one-to-many relationships with a
third table. For example, the Orders table and the Products table have a many-to-
many relationship that's defined by creating two one-to-many relationships to the
Order Details table. One order can have many products, and each product can appear
on many orders.

Relationships play very important role to bring the information from different sources at
a common place. After we make relationships, we can make a form, query or report to
display the information from different tables.

Define relationships between tables

Points to remember
• When you create a relationship between tables, the related fields don't have to
have the same names.
• However, related fields must have the same data type unless the Primary key
field is an AutoNumber field.
• You can match an AutoNumber field with a Number field only if the FieldSize
property of both of the matching 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. Even when both matching
fields are Number fields, they must have the same FieldSize property setting.

STEPS TO DEFINE A ONE-TO-MANY OR A ONE-TO-ONE RELATIONSHIP

I. Close any tables you have open. You can't create or modify relationships
between open tables.
II. Press F11 to switch to the Database window (A window, which appears when
we open and Access database or an Access project. It displays shortcuts for
creating new database objects and opening existing objects)
III. Click Relationships on the database toolbar, Figure 67.

Figure 62

36
IV. If you haven't yet defined any relationships in your database, the Show Table
dialog box is automatically displayed.

If you need to add the tables you want to relate and the Show Table dialog box
isn't displayed, click Show Table on the toolbar.

V. Double-click the names of the tables you want to relate, and then close the
Show Table dialog box. To create a relationship between a table and itself, add
that table twice.
VI. Drag the field that you want to relate from one table to the related field in the
other table.

To drag multiple fields, press the CTRL key, click each field, and then drag them.

In most cases, you drag the primary key field (which is displayed in bold text)
from one table to a similar field (often with the same name) called the foreign key
in the other table.

VII. The Edit Relationships dialog box is displayed. Check the field names
displayed in the two columns to ensure they are correct. You can change them if
necessary. Set the relationship options if necessary.
VIII. Click the Create button to create the relationship.
IX. Repeat steps 5 through 8 for each pair of tables you want to relate.

When you close the Relationships window (A window in which we view, create,
and modify relationships between tables and queries), Microsoft Access asks if
you want to save the layout. Whether you save the layout or not, the relationships
you create are saved in the database.

Note You can create relationships using queries as well as tables. However, referential
integrity (Rules that we follow to preserve the defined relationships between tables when
we enter or delete records) isn't enforced with queries.

Here the above procedure is explained pictorially, Figure 68 to Figure 72.

Let us take a database (IGNOU), having tables tblAddresses, tblStudent as shown below

Figure 68 37
Now we click on relationships icon on the database toolbar. Show table dialog box is
automatically displayed as shown below

Figure 69

Select table to make relationship and click on add button or just double click on the tables
one by one.

Then close the show table dialog box.

Figure 70

Drag the field you want to relate from one to another table to the related field in the other
table (To drag multiple fields, press the CTRL key, click each field, and then drag them.

In our case click on rollno in table tblAddresses and drag the rollno field and release the
mouse button on ID field of table tblStudent.

The edit relationship dialog box will be displayed.

38
Figure 71

Click on create button to create relationship.

Figure 72

39
Check your progress 2

Question 1: Fill in the blanks.

1. _____is a data base object which is used as front end application


2. A form is a type of a database object that is primarily used to enter or display
_____in a database.
3. You can also use a form as a _____ that opens other forms and reports in the
database.
4. Generally forms are bound to one or more tables and _____in a database.
5. A form may or may not contain all the _____of the tables or queries with which it
is associated.
6. One can enter records _____in the table by opening the table using following
steps
7. We can also enter records in the table, using _____.
8. In a _____relationship, each record in Table A can have only one matching record
in Table B, and each record in Table B can have only one matching record in
Table A.
9. One-to-one type of _____is not common, because most information related in this
way would be in one table.
10. You might use a one-to-one relationship to divide a table with many ______, to
isolate part of a table for security reasons, or to store information that applies only
to a subset of the main table.

Question 2: What is one to many relationships?

40
4.9 USING PRIMARY AND SECONDARY KEYS IN
TABLE

Primary key is used to identify a record uniquely in a table. Primary key prevents
duplicate values in a table for the attribute/column/field which is designated as primary
key. We can not leave any value blank (Null) in the column which is designated as
primary key. A powerful database like Microsoft access is having ability to quickly find
and gather the required information from multiple tables using queries, forms and reports.
To make it happen, each table should include a field or group of fields which identifies
each record uniquely in the table.

We should be careful to assign primary keys in the table. There is always only one
primary key in the table which can be a simple or composite in nature. For example let’s
we consider a table as given below, Figure 73.

Figure 73

In this table ID is taken as primary key. No two records will be having same value of ID
field. Thus we can uniquely find a record on the basis of any one value of ID field.

Also consider the following points regarding primary key fields.

• Name can not be considered as primary key, because two students can have same
name. If this happens then uniqueness property is violated. Same is case with
Course, Address, Phone, Result, UniversityName. Also, we should consider
future changes in the database. Suppose, if we assign name as a primary key and a
new student is admitted in the course and his name is also Arun, in that case
access will not allow that new record to be added in the table.

41
• Another important point is if multiple fields are having ability to be primary key,
in that case we should select a field which is having small size and ease of access.
In the above table ID and Rollno both fields are having ability to be primary key,
because no two students will be having same value of Rollno. But if choice is
given, one should choose ID as primary key being small in data size.

• Also, in a table if multiple fields are having uniqueness property they are called
candidate keys, and only one is selected as primary key. The rest of the keys are
called alternate keys.

• Also there may be situations when no single field is having ability to preserve
uniqueness. In that case two or more fields are joined together to preserve
uniqueness property to find a record uniquely on the basis of unique value
combination of such keys. This type of joint key called composite or concatenated
key. For example let us consider the following table.

Name Surname Course Marks Result


Mr. Arun Bakshi Ph.D 900 PASS
Ms. Jaya Bakshi MBA 870 PASS
Ms. Chhavi Bakshi M.Tech 888 PASS
Mr. Mukesh Bakshi B.Tech 678 PASS
Mr. Deepak Kumar MBA 877 PASS
Ms. Gunjan Gautam MCA 678 PASS
Mr. Mohit Gautam MCA 987 PASS
Mr. Manoj Garg MCA 786 PASS
Mr. Manoj Banga M.SC 898 PASS
Mr. Rajesh Kapoor Ph.D 897 PASS

In the above table neither Name nor Surname is having uniqueness property. But
if we join Name and Surname we can preserve the uniqueness property. Thus if
we make primary key by the combination of Name and Surname, that will be
named as composite key. But there may be a situation when even, this
combination fail i.e. if two students are having same Name and Surname also. In
that case go for AutoNumber primary keys, explained ahead.

Three types of primary keys used in the Microsoft Access are

Single-field primary keys

When a single field is having ability to preserve uniqueness property for data
values contained in that field and also there is no Null value in the field, it is
called single field primary key. For example : Rollno, University Enrollment No,
Pancard No, Bank Account No, Social Security Number (SSN) etc.

Multiple-field primary keys

42
In situations where you can't guarantee the uniqueness of any single field, you
may be able to designate two or more fields as the primary key. The most
common situation where this arises is in the table used to relate two other tables in
a many-to-many relationship. For example, an Order Details table can relate the
Orders and Products tables. Its primary key consists of two fields: OrderID and
ProductID. The Order Details table can list many products and many orders, but
each product can only be listed once per order, so combining the OrderID and
ProductID fields produces an appropriate primary key.

OrderID ProductID
10001 P101
10002 P102 Each product can be listed
10003 P101 only once per order.
10001 P103
10002 P104
10001 P105

Also, if you feel difficulty to decide the combinations of fields to make primary
key, it also always a good decision to add an AutoNumber, a field data type that
automatically stores a unique number for each record as it's added to a table.
Three kinds of numbers can be generated: sequential, random, and Replication
ID.) field and designate it as as primary key

AutoNumber primary keys

An AutoNumber field can be set to automatically enter a sequential number as


each record is added to the table. Designating such a field as the primary key for a
table is the simplest way to create a primary key. If you don't set a primary key
before saving a newly created table, Microsoft Access will ask if you want it to
create a primary key for you. If you answer Yes, Microsoft Access will create an
AutoNumber primary key.

We can conclude, Primary key = Unique + Not Null

SECONDARY KEYS : Secondary key is an attribute or a combination of


attributes that may not be a candidate key but classifies the entity set on a particular
characteristic. For example the entity set STUDENT having the attribute city, which
identifies by its value which means all instances of STUDENT who belong to a given
city. More than one student may belong to a city, so the city attribute is not a
candidate key for the entity set STUDENT, since it can not uniquely identify an
individual student. However, the city attribute does identify all students belonging to
a given city. Hence it can be considered as a secondary key.

43
4.10 IMPORTING AND EXPORTING DATA FROM AND
TO EXCEL
Import or link data from a spreadsheet

To use Import utility to import data from spreadsheet to access database, we should
ensure that in the spreadsheet data is arranged in an Microsoft Access compatible format
(in an appropriate tabular format) i.e. spreadsheet has the same type of data in each
respective field/column and the same fields in each row.

Steps to import data from spreadsheet.

I. Open a database, or switch to the Database window for the open database.
II. Do one of the following:
a. To import a spreadsheet, on the File menu, point to Get External Data,
and then click Import.
b. To link a spreadsheet, on the File menu, point to Get External Data,
and then click Link Tables.
III. In the Import (or Link) dialog box, in the Files of type box, select Microsoft
Excel (*.xls).
IV. Click the arrow to the right of the Look in box, select the drive and folder
where the spreadsheet file is located, and then double-click its icon.
V. Follow the directions in the Import Spreadsheet Wizard dialog boxes. If you
are importing from a Microsoft Excel version 5.0 or later workbook, then you
can import from one worksheet within a workbook. You cannot import from
any other multiple-spreadsheet files, such as Microsoft Excel version 4.0
workbooks. To import from these files, you must first save each spreadsheet as
an individual file.

44
Figure 74

Figure 75

45
Figure 76

Figure 77

Figure 78

46
Figure 79

Figure 80

Figure 81

47
Figure 82

Figure 83

Figure 84 48
Exporting to Microsoft Excel or another spreadsheet program.

There are three ways you can use Microsoft Access data with Microsoft Excel or another
spreadsheet program:

• You can export a datasheet as unformatted data to Microsoft Excel or another


spreadsheet program.
• You can save the output of a datasheet, form, or report directly as an Excel (.xls)
file or worksheet. This way, you can preserve most formatting, such as fonts and
colors. Report group levels are saved as Excel outline levels, and a form is saved
as a table of data.
• You can also export the data from a table, query/view, datasheet, form, or report
to an XML file which can then be imported into Excel.

Figure 85

Figure 86

49
Figure 87

Figure 88

Figure 89
50
Figure 90

Figure 91

Figure 92

51
Notes

• You can import or link all the data from a spreadsheet, or just the data from a
named range of cells. Although you normally create a new table in Microsoft
Access for the data, you can also append the data to an existing table as long as
your spreadsheet column headings match the table's field names.
• Access attempts to assign the appropriate data type to imported fields, but you
should check your fields to make sure that they are set to the data type you want.
For example, in an Access database, a phone number or postal code field might be
imported as a Number field, but should be changed to a Text field in Microsoft
Access because it is unlikely that you will perform any calculations on these types
of fields. You should also check and set field properties, such as formatting, as
necessary.

Check your progress 3

Question 1: Fill in the blanks

1. ______is used to identify a record uniquely in a table.


2. We can not leave any value ______ in the column which is designated as primary
key.
3. To use ______ utility to import data from spreadsheet to access database, we
should ensure that in the spreadsheet data is arranged in an Microsoft Access
______format
4. There are ______ ways you can use Microsoft Access data with Microsoft Excel
or another spreadsheet program.
5. You can ______a datasheet as unformatted data to Microsoft Excel or another
spreadsheet program.
6. You can save the output of a datasheet, form, or report directly as an ______file.
7. You can ______or link all the data from a spreadsheet, or just the data from a
named range of cells.
8. Access attempts to assign the ______data type to imported fields, but you should
check your fields to make sure that they are set to the data type you want.
9. You should also check and set field______, such as formatting, as necessary.
10. ______is an attribute or a combination of attributes that may not be a candidate
key but classifies the entity set on a particular characteristic.

Question 2: What are auto number primary keys?

4.11 SUMMARY

In this unit, students have learnt to create a database and to store data in tables in an
organized manner. Basic concepts of database are also discussed in this unit, to make
students aware of database terminology also. The different objects of MS Access
database like tables, reports, queries and forms are also covered from importance,
relevance to their creation procedures. Primary and secondary keys usage is also

52
discussed with illustrations to give in depth understanding of such objects. The
techniques to import as well to export data from MS Access as also covered with
pictorial illustrations to make students through with the use of such techniques.
Relationships which are very important and significant features of database is also
covered with an easy step by step learning technique.

4.12 ANSWERS/SOLUTIONS
Check your progress 1:

Answer 1: Fill in the blanks.

1. Table
2. Table
3. Cell
4. Relational
5. Information
6. Reports
7. Effective
8. Tables, query
9. Queries.
10. Report.

Solution 2:
Crosstab queries are used for easier analysis of data. Such queries are used to calculate
sum, average, count, and such kind of totals for data which is grouped by two information
patterns, one down the left side of the datasheet and another across the top.

Check your progress 2:

Answer 1: Fill in the blanks.

1. Form
2. Data
3. Switchboard
4. Queries
5. Fields
6. Directly
7. Forms.
8. One-To-One
9. Relationship
10. Fields

53
Solution 2:

Relationship between Manager and employees i.e. one manager can have many
employees in his department. Also, a one-to-many relationship is the most common
type of relationship. In a one-to-many relationship, a record in Table A can have
many matching records in Table B, but a record in Table B has only one matching
record in Table A.

Check your progress 3

Answer 1: Fill in the blanks.

1. Primary key
2. Blank
3. Import ,compatible
4. Three
5. Export.
6. Excel
7. Import
8. Appropriate
9. Properties
10. Secondary key

Solution 2:

An AutoNumber field can be set to automatically enter a sequential number as each


record is added to the table. Designating such a field as the primary key for a table is the
simplest way to create a primary key. If you don't set a primary key before saving a
newly created table, Microsoft Access will ask if you want it to create a primary key for
you. If you answer Yes, Microsoft Access will create an AutoNumber primary key.

4.13 FURTHER READING


1. Teach Yourself Microsoft Access 2000, in 24 Hours, SAMS, Techmedia
2. Teach Yourself Microsoft Office 2000, in 24 Hours, SAMS, Techmedia
3. Microsoft Access 2003 Forms, Reports, and Queries, Mcfedries, Paul,, Pearson
Education
4. Access 2003 bible By Cary N. Prague, Michael R. Irwin, Jennifer Reardon
Access, Wiley Publishing, Inc.
5. http://agtr.ilri.cgiar.org/Compendia/Doc/Basic%20Introduction%20to%20MS-
Access.pdf
6. http://library.med.utah.edu/ed/eduservices/handouts/access_web/accesstutorial_ba
sics.pdf

54

You might also like