Professional Documents
Culture Documents
This table contains information about students roll no, name and attendance. Suppose we
have another table containing the information about student’s marks in final exam.
Roll No Marks
Now it is obvious that only those students will appear in exam that will have their records
in first table. So each record in table one is connected with table two. In this case we say
4 Institute of Management & Information Technology
that these two tables have one-to-one relationship. Now for example you cannot enter a
roll no in table two which is not present in table one. We have more types of relationships
among tables. These are one-to-one, one-to-many, many-to-one, many-to-many and
intermediate relations.
Relationship Definition
One-to-One 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.
1
Table 2
Roll No Marks Division
One table shows two particulars of entity student while other shows student marks and
division (apart from primary key), say in mid term examination. These two tables are
linked with each other in one-to-one relation. One record in table 1 can share only one
record in table 2. When in display in MS Access in data sheet view, table 1 will show +
sign in start of its every row (record). Clicking on this sign will display the related
contents on other table.
Remember also you have to link ‘primary key’ of table 1 to ‘primary key’ of table 2 if
you are going to make one-to-one relationship between then.
Institute of Management & Information Technology 5
One-to-Many Relationship:- Keep in mind that concept of one-to-one relationship of
previous example and now we will go towards one-to-many type of relationship. Now if
one record in one table can share more than one record in table 2,it is said to be one-to-
many relationship. In this type of relationship between tables one table’s primary key will
be foreign key to other table.
Table 1
Roll No Name Age
Table 2
ID Subject Roll No
Concentrating on these two table example will unravel that these two tables
have one-to-many relationship. Primary key to table 1 is acting as an ordinary key in
table 2. It is now called foreign key in tale 2. Roll No in table 1 can have only one value
but in table 2 it can have more than one value because it is not primary key there so one
students can have as much subjects to study as he wants.
Many-to-Many Relationship:- If many records from one table can share many records
in another table, than this will be many-to-many relationship.
Students
Roll No Name Age
Teacher
ID Subject Roll No
6 Institute of Management & Information Technology
In this example we can see that student-teacher relationship is many-to-many
relationship. Every student can ask anything to any teacher, also any teacher can teach
many or all students.
Practically two tables cannot relate to each other in many-to-many relation
fashion. Another table will mediate in them. It is one-to-many relationship from each
table with that third mediatory table. Here is an example.
Order ID Product ID
1 1
2 2
3 1
3
Order ID Customer ID
1
2
3
4
5
Note that one order can have many products and each product can appear on many orders.
Defining relationships among tables:- We will now learn the actual method or
procedure of making relations between tables. Consider that you have two tables in
database. Now follow these steps.
1) Close any tables if open. Now only database window will be visible.
2) Click on “relationship” button on database toolbar. Now relationship window will
appear.
3) Now relationship window will appear and also a window containing all objects
present in data base. Add these two tables to this window by double clicking on
each table turn by turn.
You will now see two small windows in this “relationship” window. These
windows are representatives of two tables. Each window show all fields name of its
table. Primary key will appear in bold letters.
Institute of Management & Information Technology 7
Now there are two possibilities which we will discuss now.
(1) One-to-One relationship. (2) One-to-Many relationship.
One-to-One Relationship:-
4) Click on any table’s Primary key and keep mouse button pressed. Go to other
table’s Primary key and release button.
5) An information dialogue box will appear. Click on “Enforce Referential Integrity”
and then on “Cascade update related fields” and on “Cascade delete related
records” options and click on “create”.
One-to-Many Relationship:-
6) Click on any table’s primary key and keep mouse button pressed. Go to any field
of other table (foreign key) and release button.
7) An information dialogue box will appear. Click on “Enforce Referential Integrity”
and then on “Cascade update related fields” and on “Cascade delete related
records” options and click on “create”.
Note also that each “Edit Relationship” window shows the type of relationship at the
end.
Adding a field:- To add a field in last, just type the name of the field at the end of
previous fields and new field will be created.
Suppose you want to insert a new field between two existing fields, set cursor in lower
field and then open “Insert menu”, and click “Rows”.
Removing a field:- To remove a field, just set cursor in that field and choose “ delete
rows” from the edit menu. Another shortcut is right click on row’s left most space a menu
will appear, choose “delete rows”.
8 Institute of Management & Information Technology
Moving or copying a field:- To move a field from its present location to new location,
just drag it with left mouse button from left most space of row and release button where
you want to place it. If you want to make a copy of a field, just click on this space again
and choose “copy” from edit menu and paste it at new empty location or between fields.
Making changes in Datasheet view:- You can use table’s datasheet view for changing
table’s properties in any of the two ways. You can change some things about table in
datasheet view and those all be in its basic structure. Some changes will be visible in
datasheet view only and will not affect the structure of table. Let us consider these turn
by turn.
Changes in structure of table:- you can use table’s datasheet view to do these
operations.
i. Renaming fields.
ii. Adding fields.
iii. Deleting fields.
iv. Changing the place of columns.
These changes will affect table’s structure.
Renaming fields:- For renaming the fields, just double click on its title and it will be
ready for new name. Just type any new name and press enter.
Adding fields:- You can add new columns or fields from datasheet view. Just right click
on any field’s title you will see an options menu, choose “Insert column”. Click on it and
new field will be inserted to the left of the column you have selected.
You can add field from “Insert” menu. Open insert menu and click on “column”.
Deleting fields:- You can delete any field by right clicking on its title and choosing
“delete column” or just click on any field and select “delete field” from “edit” menu.
Changing place of column:- For changing place of any field or column, just click its
title (for selecting whole field) and then drag it any where between any two tables or
columns.
Remember once again that these changes are permanent and could be checked from
table’s design view.
Sorting your information:- You can rearrange information after entering in any field.
You have two options for arranging the information. You can arrange it in “Ascending
Institute of Management & Information Technology 9
order” or “Descending order”. If you will arrange field in Ascending order all entries in
that table will be sorted from little to biggest.
For sorting in ascending fashion, highlight that field and press ascending sort button
present on database toolbar.
A
Z
Ascending sort button
And if you will use Descending sort button, value will be sorted from maximum to
minimum.
Z
Descending sort button
A
If you will text field it will sort it from A to Z if you will sort it in ascending way and Z
to A if in descending order. Also if you will sort ascending a date field, it will rearrange
in past to future and vice versa.
Finding matching record in a table and replacing it with another:-
You can find any record in a table by just using find option. You can find any record
present in any field of a table. Just make a table and then after opening its datasheet view
click on the find button present on the database toolbar.
Query:- We can create Query by design view and by wizard.
How to create query by design view
i. Click on Query.
ii. Double click on Query by design view.
iii. Select the table and click on add button.
iv. Double click on the required fields.
v. Type the criteria.(If required)
vi. Run the Query from tools menu.
vii. Close the Query.
viii. Click yes.
ix. Type Query name. then OK.
Field Name Address Phone No Program City
name
Table
Criteria ICS-II
OR
In above Query we have requested to display those students information who are in
ICS-II.
Operators:-
AND= Logical operators
OR = Logical operators
>, <, >, <, Between, <>, (Comparison Operators).
10 Institute of Management & Information Technology
Like:- We use Like for alphabets by which the word starts (Like A) Ahmed and
finishes by Alphabet (like d) Good.
Making queries having new calculated fields:- Doing calculation on the data stored
tables is one of the most important features of the computerized database. Like
Table contains the attendance record for five students for three subjects. We now will
calculate the students’ average attendance. For that purpose we will make a query. Select
all fields from attendance table to query. And after, that type this expression in a new
field in query design view.
“sum of attendance: ([attend_phy]+[attend_comp]+[attend_eng])”
Pay Rule
First in table we just Enter two fields(entity) Name and Basic Salary.
And
In Query we have to fill.
House Rent =45%
HR:[BS]*45/100
Conveyance Allowance =10%
CA:[BS]*10/100
Provident Fund =7%
PF:[BS]*7/100
Income Tax =5%
IT:[BS]*5/100
Net Detection
ND:[PF]+[IT]
Net Salary
NS:[GS]-[ND]
Action Query
Update Query
Make table Query
Append Query
Action Query: An action query is a query that makes changes to or moves many
records in just one operation. There are four types of action queries:
• Delete Queries A delete query deletes a group of records from one or more
tables. For example, you could use a delete query to remove products that are
discontinued or for which there are no orders. With delete queries, you always
delete entire records, not just selected fields within records.
Institute of Management & Information Technology 11
• Update Queries An update query makes global changes to a group of records in
one or more tables. For example, you can raise prices by 10 percent for all dairy
products, or you can raise salaries by 5 percent for the people within a certain job
category. With an update query, you can change data in existing tables.
• Append Queries An append query adds a group of records from one or more
tables to the end of one or more tables. For example, suppose that you acquire
some new customers and a database containing a table of information on those
customers. To avoid typing all this information into your own database, you' d like
to append it to your Customers table.
• Make-Table Queries A make-table query creates a new table from all or part of
the data in one or more tables. Make-table queries are helpful for creating a table
to export to other Microsoft Access databases or a history table that contains old
records.
Update Query:-
i. Double click on create Query by design view.
ii. Add the table.
iii. Double click on required field.
iv. Click on update Query in Query menu.
v. Type the criteria and update.
vi. Run the Query.
Delete Query:-
i. Click on Query.
ii. Double click on create Query by design view.
iii. Add the tables.
iv. Choose delete Query from Query menu.
v. Double click the required fields.
vi. Type the criteria.
vii. Run Query.
Product ID Product ID
Product Name Product Name
Quantity Quantity
Price Price
Month Month
Form
Form in any database work as front hand tool. We interact with the tables and queries
(basic place holds for data) through forms. After making tables and forms in database we
will only see forms and tables will remain hidden from our normal database view. Also
we can not only enter but view data from tables through forms.
Creating forms:- We can create forms by to ways.
1. Create forms in design view.
2. Create forms by wizard.
Create forms by using wizard:- It is evident that you will create form when you have at
least one table present so first step in making a form is building a table.
After these, follow these steps.
1) Click on the forms tab present in database window.
2) Double click on the “create form by using form by wizard”.
You will see the list of all tables and queries in “Table/Queries” pull down menu. Also
note that when selected a table or query all of its columns or fields appear in the
“Available Fields” window.
3) Select the table from “Table/Queries” pull down menu.
4) Select the field you want to appear on the form and press > button.
You can choose one by one and if you want that all the fields of the table should
be added in the form then press button. At once all the fields will be
added. >>
5) After selecting field(s), Press Next button.
6) A new window will appear.
7) In this window you will see different options for columns of a table to appear on
the form.
If you will select “Columnar”, you will see the form showing only one record from the
table at a time. If you will select the “Tabular” option, you will see the form on which all
controls will be arranged like datasheet view and you will see all records of the table at
once. I will proceed here by choosing “Columnar” option.
8) After choosing “Columnar” radio button, click on next.
9) On this next window you can choose a pattern for your form.
Check your self the options and after selecting one, click on next button.
10) After that you will se the final window in form building using wizard.
11) Just click on finish.
Institute of Management & Information Technology 13
You will see the form displaying only one record at a time and also showing record
navigation options bellow the form.
You can see all records by clicking and buttons on the “Record” navigation
bar. Now you can add the records by just typing in the controls present on the form and
pressing enter key after entry in last control or you can press button also present on
the record navigation bar.
After making form, save it from “file menu’s” save option with appropriate name.
Create in design view:- Follow the steps for making form in design view.
1) Keeping in mind that you have one or more tables prior to form building, double
click on the option “Create form in design view” after clicking on the forms tab of
database window.
2) Without any further window, form will appear. You will see that this form does
not contain any controls, and any object. Now you will place the controls for the
fields of any table, and other drawing objects on it.
3) Now first for all you need controls of fields of a table on this table.
4) After highlighting this new form, click on properties button present on database
toolbar. Its shape is .
5) A new window will appear. This is the properties window for that new form.
Form formatting:- After making form by either method, we will now concentrate on the
decoration or addition of objects in form or “formatting”. We will discuss following
things.
i. Adding drawing objects.
ii. Alignment and resizing of controls.
iii. Form color and controls appearance (color and size).
Adding drawing objects:- After opening the form (or if it is still open at the first place),
click on “Toolbox” button present on the database toolbar . A new window will
appear. On this new window, titled “toolbox” you will see many buttons representing
different drawing objects. Just click them step by step and make the appropriate drawing
on form. Here is their introduction through a picture and with brief descriptions.
i. Label:- You can add label to forms for description of any thing. It is simple text
which has properties like any other text of word or excel. You can change its font
size and color too.
ii. Check box:- This control appears for the field of data type “yes/no”. Also you
can code this object in visual basic for any “yes/no” option.
iii. Unbound object frame:- You can use this option for inserting objects like Ms
Excel sheet. Clearly it is unbound object.
iv. Bound object frame:- This frame could be used for the field of any table or
query having data type of “OLE object”.
v. Line:- For inserting line.
vi. Rectangle:- For making rectangle.
vii. Text box:- You can make text box for writing some thing and also can connect
that box with a field of a table or query.
viii. Subform/subreport:- You can add more forms or reports in a form using this
option.
ix. Tab control:- You can make a page (or small area in a form) with two tab options.
You can add different kinds of controls on these two pages.
x. Image:- You can add image using this option.
Institute of Management & Information Technology 15
xi. Toggle button:- You can code this button for two positions. If pressed and if not
pressed. Also attached to the field of data type “yes/no”.
xii. Option button:- You can also code this button for two positions. This button
works with a field of data type “yes/no”.
xiii. Combo box:- You can choose one value from a field of a table through the use of
combo box.
xiv. List box:- It shows a scrollable list of value of a table’s field.
xv. Option group:- Keeping different control set as one group.
Report
We will now consider the basic definition of reports once again. Report is an
effective and in some cases necessary objects in database to represent data in printed
format. As forms are used to enter as well as view data, it does not fit fields on a “paper
like” window for printing purposes. In reports you can arrange fields and other different
controls as you think them beautiful and when printed they will sustain their shape on
paper. We will now learn to make reports in MS Access.
You can not only make reports of tables but also of queries. Data in both tables
and queries rests in columns (fields) and rows (records) so their structure is same. Report
supports both of them.
Editing report:- After making report, select that report from database window and click
on design view.
You will see the report in design view. In design view you will see different sections of
report. In “page header” section you will see the heading of each column. These labels
will appear only once in report. In detail section all records will appear and each “text
box” represents each column of table.
Like wise “page footer” section contains that material which remain same in each page’s
bottom just like word document.
Apart from “page header” section there is top most section named “report header”. You
will see the main heading of report here. By default this section contains the name of
table for which this report is made but you can change it in any way you want using
different tools. In the lowest portion you will notice the “report footer” section. You can
add any text here and that text will not appear on the bottom of report but at the end of
records. You can see the report in design view on next page.
Text size, color and font changing:- You can change the font size by selecting any text
box and just using normal font size pull down menu form formatting bar.
All other font formatting options are same as in Ms Word or Ms Excel.
Properties of separate parts of report:- You can also adjust properties of different parts
of report separately. For example you have seen the over all properties of report that were
visible on right clicking on upper left corner or report in design view. Now if you right
click on “report header” and choose properties, you will see the properties of this section
only.
Like wise you can set properties of separate sections by right clicking on them and
choosing properties from menu.
The End
Best luck