an overview of database management system
TRANSCRIPT
-
8/7/2019 An Overview of Database Management System
1/152
Training Division, NIC, New Delhi 1
MS-Access
q An Overview of Database Management System
E Components of an Information System
One of the most important functions of any computer system is to provide powerful
tool for management ofInformation System of an organization, in which raw data(Transactions as inputs) is processed to produce meaningful information (Reports as
output for different levels of management). The processed data is stored in the form of
data files usually referred as Databank. This databank becomes one of the sources of
knowledge management required for decision support for monitoring various activities
as well as strategic planning etc. Thus components of an Information system can be
categorized as follows:
Transactions Processing System for processing raw data
Management Reporting System to provide relevant reports to various levels ofmanagement
Decision Support System for management activities like, monitoring & control,
decision support and strategic planningetc.
Executive Information Systems for senior executives
In the real world environment, Information flow in the organization is horizontal (between
various applications) as well as vertical (across hierarchically organized departments /
branches etc). Thus in an organization, Information System can be designed at different
levels as follows:
Individual Applications Level
Department Level
Organization Level
Intra-organization Level
-
8/7/2019 An Overview of Database Management System
2/152
Training Division, NIC, New Delhi
MS-Access
2
Efficiency & effectiveness of any Information System very much depends upon theorganization of data files in a data bank, and the procedures adopted for data
management In this chapter basics of data management will be covered.
E Conventional Approach for Data Management
Conventionally, for each transaction processing application, separate databanks are
created, and the data is stored as sequential files, thus making the process of data
updating and retrieval very slow. Further, the following problems are also associated
with conventional way of storing the data files:
1. Data Redundancy: Since, each application has its own data files, the other users
within the department / organization can not have access to these data files. Thus
for every application separate data files are maintained, even if they are common.
This causes data redundancy, and wastage of storage space.
2. Data Inconsistency: Data redundancy leads to data inconsistency. Data
inconsistency means discrepancy in values of data elements in same data files
physically stored at different locations.3. Data Isolation: The data files of common use, can not be made available for
sharing, even if desired so.
4. Security: There can not be enforcement of centralized control on data access, as
the data files are created / duplicated as per individual applications requirements.
The decisions regarding storing the same data at multiple places are taken at
various levels by different people, which are usually of ad hoc nature. Access
controls planning becomes difficult in such situation.
5. Data Dependency : The coding in applications is very much dependent upon the
data files design. Any change in design of data files (say addition of a new field,
or deletion of a field) will warrant for changes to be made in the coding of
application also, which uses it. .
-
8/7/2019 An Overview of Database Management System
3/152
Training Division, NIC, New Delhi 3
MS-Access
6. Lack of enforcement of standards: It is very difficult to enforce standards indata files designs, as centralized view of data files is never available.
E Database Approach
The Database technology allows logical grouping ( the way, the user wants to view it,
as per specific needs of an application) of data files associated with differentapplicationsin such a way, that the above mentioned problems associated with conventional way of
data management are minimized.
A database can be defined as follows:
Database is a databank, which is managed by a single agency, and it consists ofinter-related files, in which data items are organized in such a way that one can
have random access to data, as per specific needs of the users.
Important terms associated with a database are:
Field: It is the smallest unit of data, which can be stored in a database. For example, astudents name in a universitys database would appear in the field named as
student_name. Usually the data types in a filed are Numeric, Character string, Date,
Memo, Logical, Hyperlink, Picture etc. The field is at times referred as attribute/data
element / data item also. These nomenclatures can be used synonymously.
Record: It is a collection of related stored fields. A student record may consist of
collection of fields like Students name, the course taken, the date of birth, contact
address and the grade etc.
File(Table): It is a collection of different occurrences of same type of stored record.
A file is usually referred as a Table also, it describes an entity (something, about
which data is to be stored).
-
8/7/2019 An Overview of Database Management System
4/152
Training Division, NIC, New Delhi
MS-Access
4
1 The way user wants to view it as per specific needs of the application
Database: A logical grouping of related files would constitute a database. For example,A Student file in a database may be linked to another file say Library books issue,
which keeps record of books issues to students. The two files can be linked together by
a common field say Student code, which will get reflected in Student file, as well as
Library books issue file.
Primary Key: Every record in a file usually contains at least one field that uniquelyidentifies that record for the purpose of data retrieval, and updating of values of fields
corresponding to a record. This identifier field is called the primary key, and it always
has a unique value. Combination of more that one fields to act as identifier of a record
is called Composite Primary Key.
Foreign Key: For setting relationship between two tables, there should be at least onecommon field in two tables. Usually that common field is Primary key in one table, and
it is called Foreign key in the second table. Foreign key can have repeated values also.
E Types of Data Model (based on logical1 data structuring)
Three types of common Data Models
1. Hierarchical: The hierarchical database model rigidly structures data into an
inverted tree in which each record contains two elements. The first is a single
root or master field, often called a key, which identifies the type location or ordering
of the record. The second is a variable number of subordinate fields, which define
the rest of the data within a record.
2. Network: The network database model creates relationships among data through
a linked-list structure in which subordinate records (called members) can be linked
to more than one data elements (called an owner).
-
8/7/2019 An Overview of Database Management System
5/152
Training Division, NIC, New Delhi 5
MS-Access
3. Relational: The relational database model is based on the simple concept of flattables consisting of rows and columns. In this model, a table is equivalent to a
file, row is equivalent to a record, and each column is equivalent to a field.
Relations between different tables can be set through common fields.
Comparison between the Three Models
Model Advantages Disadvantages
Hierarchical database Searching is fast and
efficient.
Access to data is predefined by
exclusively hierarchical relation-
ships, predetermined by
administrator. Limited search/
query flexibility. Not all data is
naturally hierarchical.
Network database Many more relationships
between data elements can
be defined. There is greater
speed and efficiency thanrelational database models.
This is the most complicated
model to design, implement, and
maintain. It has greater query
flexibility than hierarchicalmodel, but less than relational
model.
Relational database Conceptual simplicity is its
characteristic. There is no
predefined relationships
among data. High
flexibility in ad hoc
querying. New data and
records can be added easily.
Processing efficiency and speed
is lower. Data redundancy can
not be eliminated completely.
-
8/7/2019 An Overview of Database Management System
6/152
Training Division, NIC, New Delhi
MS-Access
6
Emerging Data Models
1. Relational MultidimensionalDatabase: Used for building Data warehouse.
2. Object-Oriented: Consists of inter-related objects, similar to entities consisting
of attributes, methods associated with the object, and its behavior).
3. Hypermedia: Stores chunks information in the form of nodes, for which links are
established by the user, as per specific needs.
4. Geographical Information Database: Used for managing locational data for
overlaying on maps and images.
5. Knowledge Database: Consists of decision rules used to evaluate situations and
help users to take decisions like an expert.
E Types of Database Architecture (based on physical locations of
the data files and data processing)
1. Centralized: A centralized database has all the related files in one physical
location. Even the processing of data is done at the centralized location. Users can
have access to the database application from remote computers / terminals.
2. Stand alone: A stand alone database has all the related files and the procedures
for processing the data at one physical location only. Others can not have accessto the database application.
3. Distributed: Database has complete copies of a database, or portions of a database,
in more than one location. In this type of setup, even the processes associated
with data management are distributed in various computers over network, usually
close to the user.
-
8/7/2019 An Overview of Database Management System
7/152
Training Division, NIC, New Delhi 7
MS-Access
There are two types of distributed databases:
Replicated: A replicated database has complete copies of the entire database in
more than one locations, primarily to alleviate the single-point-of-failure problems
of a centralized database as well as to increase user access responsiveness.
Partitioned: Database is subdivided, so that each location has a portion of the
entire database. The divided portions of database are locally maintained and are
made available to others also for retrieval and further processing etc.
Client-Server: The present trend is to build Client / Server based databases, in
which common use data is stored on the server computer, and local requirement
data is stored on client systems. Usually, the processes at client machine, requestserver to provide required data. The processes at server end make the required data
available at client computer for further processing. This is a typical example of
distributed database.
In a nutshell, database technology allows an organizational data to be processed asan integrated whole. It reduces artificiality imposed by separate files for separate
applications and permits users to access data more naturally. Now let us look into
the procedures associated with Database Management and the tools available to
do so.
-
8/7/2019 An Overview of Database Management System
8/152
-
8/7/2019 An Overview of Database Management System
9/152
Training Division, NIC, New Delhi 9
MS-Access
2. Data Definition Language (DDL): It defines the structure of database, and theway how, each data item appears in the database. DDL provides link between
logical and physical views of the database.
3. Data Manipulation Language (DML): Data Manipulation Language of DBMS
has the capability to write procedures for automating various DBMS functions
as mentioned above, as per user/application requirements. It can be used with
any other application language (3rd generation/4th generation) also.
4. Structured Query Language( SQL): It is the most popular Relational Data-
base language, which allows the user to request for required information in most
natural way. It actually combines both DML & DDL features of DBMS. The
syntax of SQL commands is independent of Relational database brand.
5. Data Dictionary: It stores definitions of data fields, their standard names, aliases,
associated business functions, data ownership details etc. Data Dictionary helps
in maintaining data consistency, enforcement of standards, avoid duplicacy. It
also enables independence of applications design from database design.
Commonly used Relational Database Management Systems
Name of DBMS Database Architecture
MS Access Stand alone / Distributed Architecture based
(as Client systems only)
Oracle Mainly Client Server / Centralized Architecture based;
Stand alone PC version also is available
SQL Server Client Server / Centralized Architecture based
UNIFY Client Server / Centralized Architecture based
Visual Foxpro Client Server / Centralized Architecture based
-
8/7/2019 An Overview of Database Management System
10/152
Training Division, NIC, New Delhi
MS-Access
10
Database Systems: Advantages in a Nutshell
1. Better planning of corporate database
2. Enforcement of standards
3. Transparency
4. Better control of data by providing appropriate access controls
5. Problems like redundancy / inconsistency can be minimized
6. Easy enhancement of database is possible without disturbing the existing working
applications.
7. Improved security
8. Enhanced data integrity
9. Reduced application development and maintenance costs
10. Better / Automated backup and recovery procedures
E Getting Started with Database Design
Conceptual DesignTo begin with, one needs to be clear about the Information System requirements, for
which database and the procedures are to be designed. This can be done by adopting
systematic technique2 for structured analysis. The output of this process is known as
System Requirements Specifications (SRS). It mainly consists of:
1. A well defined objective of database application2. List of agencies who supply inputs
3. List of agencies / roles who receive reports
4. List of expected output reports and their layout
5. List of inputs transactions & data entry forms layout
2 Detailed explanation of this technique is beyond the scope of this document.
-
8/7/2019 An Overview of Database Management System
11/152
Training Division, NIC, New Delhi 11
MS-Access
1. Entity Relationship Diagram
The Entity Relationship (E-R) Diagram of a database is a model of the database
from the user or business perspective. It identifies various entities about which
data needs to be stored, and also the relationships between those entities.
For example, in Library Information System, we should have two entities about
which data needs to be stored in the database. These are students and the books.
Since, a student can get issued more than one books at a time, and a book can be
issued to many students at different issue dates, the relationship between the two
entities will be represented as follows:
Student BooksGets issued
MM
6. List of major processes7. Layout of User Interfaces to link various processes
8. List of entities (something that can be identified in the users work environment
and whose data should be stored in the database)
9. List of properties / attributes associated with the entities
10. Conceptual database design including the logical view of data files along with
associated data elements
In this section, conceptual database design only will be discussed.
The conceptual database design is independent of type of type of DBMS. It is done in
two stages as follows:
-
8/7/2019 An Overview of Database Management System
12/152
-
8/7/2019 An Overview of Database Management System
13/152
Training Division, NIC, New Delhi 13
MS-Access
Graphical Illustration:
Student Table
Issue Table
Books Table
Student-
Code
Book-Code Issue-date Status
1 1 12/10/20011 2 14/08/2002 Returned
2 2 14/08/2002
Book-code Book Name Author Edition Cost
1 Visual Basic I.K. Jain 1998 500
2 MS Access-An
Overview
R.P. Singh 1997 200
3 --- --- --- ---
Student-
Code
Student
Name
Class Date of birth Address Email- address
1 Shayam 1st
Year
11/05/1985 12, 2nd
Street,
Janpath, New
Delhi
2 Ashish 2nd
Year
21/07/84 11, Sector 7,
Vikas Puri,
New Delhi
3 --- --- --- --- ----
4 -- -- -- -- --
-
8/7/2019 An Overview of Database Management System
14/152
Training Division, NIC, New Delhi
MS-Access
14
Physical Design
In the physical design, the actual structures of tables are created using a particular DBMS
package. The physical design shows how the files, records, fields are actually stored on
the physical storage media, depending upon the type of database, the DBMS supports.
This physical design giving complete logical view ( the way user wants to view it) of
the database, is called schema.
Various applications developers have the choice of getting different logical views (which
may be even partial) of the same database. They can customize these views as per their
specific needs. Such logical view is called subschema. DBMS provides tools for
creating the subschemas .
This characteristic of DBMS makes the database design independent of
applications design. That means, any changes made in the database design will notaffect already working applications, unless the data elements, being used by them
are deleted from the database.
-
8/7/2019 An Overview of Database Management System
15/152
Training Division, NIC, New Delhi 15
MS-Access
E Getting Started with MS-Access
MS Access is a Relational DBMS, for windows based desktop database applications,
which may be stand alone or distributed over network. In a Client-Server environment,
it is used to maintain database at the client end.
Database in MS Access is referred as a collection of data , procedures, reports, interfacesetc. related to a particular purpose. It has mainly the following components.
Tables to contain data in the form of records / fields.
Forms to manipulate data and user interfaces to link forms, sub forms or processes.
Queries to create logical view of data and also to find and retrieve desired data based
on various conditions.
Reports to print information in pre-laid formats
Pages to publish the reports / queries output on Web
Macros to club more that one operations and automate their executions
Modules to add more functionality by writing codes using Visual Basic for Applications
(VBA), which is scripting language integrated with MS Access. It is similar to Visual
Basic.
-
8/7/2019 An Overview of Database Management System
16/152
-
8/7/2019 An Overview of Database Management System
17/152
Training Division, NIC, New Delhi 17
MS-Access
7. List of entities identified ( about which the data is to be stored )
Employee details
Leave details
8. List of data items associated with above entities
Employee: Name, Designation, Date of Joining, Skill, Email address,employee photograph etc.
Leave details: Name of the employee, Designation, Leave type, Duration, Start
Date, End Date, balance leave at credit.
9. Entity - Relationship Diagram ( Conceptual Design of database)
Employee TakesLeave
10. After Normalization process, we will get the conceptual design in the form
of the following two tables.
Employee table consisting of fields: Employee-code, Name, Designation, Date
of Joining, Skill, EL at credit, CL at credit, RH at credit,HPL at credit, Salary, Email address , employee
photograph etc.
Here Employee-code is the Primary Key.
-
8/7/2019 An Overview of Database Management System
18/152
Training Division, NIC, New Delhi
MS-Access
18
Leave table consisting of fields: Employee-code, Leave type, Duration, Start-Date,
End Date
Here Employee-code + Start-Date is a Composite Key, and Employee-Code is
Foreign Key.
11. User Interfaces Design
Maintain Employees data
Enter Leave Details
Year End Processing
Reports / Queries
Reports Page Employee Report
Creating Employee Label
Leave Details of Individual
employee
Enter Leave Details
Form for entry of multiple
leave details of an employee
Maintain Employee Data Add New Employee
Modify Employee Data
Delete Employee Data
-
8/7/2019 An Overview of Database Management System
19/152
Training Division, NIC, New Delhi 19
MS-Access
Few suggested enhancements to the above mentioned case study, which can bedone by participants as assignment.
Add login screen for screen for maintaining employee data to enforce Access
controls.
Calculate gross pay of employees and generate pay slips by automatically
calculating DA from the basic salary.
Add a filed in Leave table to set hyperlink to leave sanction order (MS Word
file).
Generate MS Word document for leave details statement for every employee
with a provision to send it as an attachment to email of that employee (You cal
use Mail merge option).
Publish employees list on Web along with their leave at credit.
Create a new table containing department code, and other details. In employee
table, add a field for department, to which employee belongs. In the properties
of this field, pickup the values for department field from the department table
through lookup Wizard.
Develop a module for periodic backup of tables. This process should get triggered,
on mouse click on the main menu.
Develop a module for automatic backup of tables. This process should get
triggered, automatically on 1st day of every month.
On the similar lines of the case study, you can also develop a database application
relevant to your work area.
-
8/7/2019 An Overview of Database Management System
20/152
-
8/7/2019 An Overview of Database Management System
21/152
Training Division, NIC, New Delhi 21
MS-Access
Figure 2
Select the folder name in Save in option.
Type Employeeunder File name.
ClickCreate. Employee database window will open as shown in Figure 3.
To open table
for data entry
To make modification
in design of table
To create new table
Figure 3
-
8/7/2019 An Overview of Database Management System
22/152
Training Division, NIC, New Delhi
MS-Access
22
After the database has been created, different objects of the database like Tables, Queries,
Forms, Reports etc. can be created by selecting appropriate tabs.
Note: We are going to refer to this database window in later part of the workbookalso.
E Ways of Creating a Table
Create table in design view
In this option, table has to be created from scratch, in which its fields names, their data
types and properties have to be entered.
Create Table by using Wizard
In this option, wizard dialog box will open with the steps provided to create a table.
Create table by entering data
In this option, only data has to be entered and it will take fields names as field1, field2
and so on and data type it will take automatically based upon data entered (one canrename the fields names, if required).
E Creating New Table
Double clickCreate table in Design View.
Note: Another way to get Design view for new table,
ClickNew>>Design View>>OK.
New Table dialog box will appear as shown in Figure 4.
-
8/7/2019 An Overview of Database Management System
23/152
Training Division, NIC, New Delhi 23
MS-Access
Figure 4
As shown in Figure 5, enternames of fields in Field Name column, type of data
to be entered in fields in Data Type column and enter description of fields in
Description column if required.
Figure 5
MS A
-
8/7/2019 An Overview of Database Management System
24/152
Training Division, NIC, New Delhi
MS-Access
24
ESaving the Table
ClickFile>>Save. The dialog box as shown in Figure 6 will appear.
Figure 6
Type the Table name as Employee and clickOK. The dialog box as shown in
Figure 7 will appear.
Figure 7
Select No.Table will be saved with the name Employee. Close the table Employee.
E Adding Records to a Table
Select table Employee from database window.
ClickOpen.Datasheet View of the table will open as shown in Figure 8.
MS Access
-
8/7/2019 An Overview of Database Management System
25/152
Training Division, NIC, New Delhi 25
MS-Access
Figure 8
Start entering the data from the cursor placed at the first blank record .
The following data may be entered as shown in Figure 9.
Figure 9
Save and Close the table window.
E Deleting Records
Click on the record to be deleted.
Select Edit>>Select Record. The record gets selected as shown in Figure 10.
Figure 10
MS Access
-
8/7/2019 An Overview of Database Management System
26/152
Training Division, NIC, New Delhi
MS-Access
26
Click Edit>>Delete Record from the menu bar, the record will be deleted.
Note : To delete all record, clickEdit>>Select All and press Delete button. But
dont try this option otherwise you will lose whole data of that table.
E Editing Data in Tables
Cutting & Pasting Or Copying & Pasting Data
Select the record to be cut or copied.
Select Edit >> Cut (for cutting data) or Edit>>Copy (for copying data). Take the cursor to a new position in the table where the record is to be copied.
Select Edit>>Paste.
Locating Data
Select the field where the data has to be searched, by clicking the Field Heading
OR put the cursor anywhere in the column where the data has to be searched.
Click Edit>>Find. The Find and Replace dialog box appears as shown in
Figure 11.Click here to select the field.
Figure 11
MS-Access
-
8/7/2019 An Overview of Database Management System
27/152
Training Division, NIC, New Delhi 27
MS-Access
Enter a string to search for, in the Find What: option, say ANIL. In Match option, select any of the three category provided.
Choose Find Next to search for more records.
Select Cancel to stop the search and close the dialog box.
Replacing the existing data
Click on the field name where the data is to be replaced. For example, click on
Designation field
Select Edit>>Replace.The Replace dialog box as shown in Figure 12 will appear.
Figure 12
Type SAin Find What field. Click on the Replace With field. Type SSA.
Click on Find Next button. It will find the first occurrence of the data.
Click on Replace to replace the data in that field.
Click on Find Next to find and then clickReplace to replace the next occurrenceof the data (If required, clickReplace All to replace all such occurrences).
Close the Find and Replace dialog box by clicking the Close button.
MS-Access
-
8/7/2019 An Overview of Database Management System
28/152
Training Division, NIC, New Delhi
MS Access
28
ESorting Data
Data stored in a table can be sorted on text, numbers, or date fields in ascending order
(A to Z, zero to 9, or earliest to latest date). Or, you can sort in descending order (Z to A,
9 to zero, or latest to earliest date).
Click on the Field on which the records are to be sorted.
ClickRecords>>Sort>> Sort Ascending from the Record menu option.The option provides you to rearrange the records Ascending/Descending on Name
field as shown in Figure 13.
Figure 13
Close the table window
ClickYes,ifchanges areto be saved in the table.
E Modifying Table Design
Select the table to be modified from the database window.
Select Design.
The table will open in Design View. The design of the fields in table can now be modified,
i.e., the fields can be deleted, added or changed according to the requirements. After
the modification, changes can be saved and the database window reappears.
MS-Access
-
8/7/2019 An Overview of Database Management System
29/152
Training Division, NIC, New Delhi 29
EPrimary Key
A Primary Key is a field (or group of fields) that uniquely identifies each record. When
primary key is created, Access will do the following things:
1. Make sure no two records in the table have the same value in the field (or group of
fields) that defines the primary key.
2. Keep records sorted (ordered) by the entries in the primary key.
3. Speed up processing.
Note: No field that is part of a primary key can be left blank during data entry.
Setting a Primary Key
Open the table in Design view.
Select the field for which primary key property has to be set.
ClickEdit>>Primary Key.
The field which is set as the primary key, will have key icon in the row selector as
shown in Figure 14.
Figure 14
Note: If the data in a table contains duplicate data for the emp_code field, the error
message will be displayed while defining the emp_code field as a primary key. To
remove the error, first remove the duplicate data and then define field as a primary
key.
key icon
row selector
MS-Access
-
8/7/2019 An Overview of Database Management System
30/152
Training Division, NIC, New Delhi30
Removing Primary Key Setting
Select the field for which primary key setting has to be removed.
ClickEdit>>Primary Key. It will remove primary key setting.
E Creating Second Table
Let us now create another table Leave with the following fields:
Emp_code Number
Type_Leave Text
Start_Date Date
Duration NumberEnd_Date Date
Save this table as LEAVE table.
Close the table design window and enter the data for this table.
It may be noted that the values of Emp-code should be the same as those alreadymentioned in the Employee table.
MS-Access
-
8/7/2019 An Overview of Database Management System
31/152
Training Division, NIC, New Delhi 31
qRelationships
In RDBMS systems, usually data is stored in more than one table, depending on the
type of information. To bring the relevant information together in a Form/Report/Query,
these tables need to be linked together.
To link the tables together Relationships are used. For example, there are two tables
Employee table, which contains employees details, and other Leave table, which containsthe information about the leaves taken by all the employees. To create a report, which
will give the details of the leaves taken by all the employees, relationship between the
two tables Employee and Leave is required. Sample report having data from both the
tables is shown in Figure 15.
Figure 15
E How it works ?
In the above example, the fields in both tables must be linked so that they show relevant
information about the employees. This linking is done by setting relationships between
tables. A relationship is created by matching data in one of the fieldsof the table
usually a field with the same name in both tables. In most cases, these matching fields
MS-Access
-
8/7/2019 An Overview of Database Management System
32/152
Training Division, NIC, New Delhi32
are the primary key3 from one table and a foreign key4 in the other table. For example,
employees can be associated with the leaves they have taken by creating a relationship
between the Employee table and the Leave table using the Emp_code (Employee Code)
field as shown in Figure 16.
3Primary key consists of one or more fields (columns) whose value or values uniquely identify eachrecord in a table. A primary key cannot allow Null values and is used to relate the table to foreign keys in
other tables.
4Foreign key is one or more table fields (columns) that refer to the primary key field or fields in anothertable. A foreign key indicates how the tables are related. The data in the foreign key and primary key
fields must match, though the field names do not have to be the same.
Primary Key
Employee Table
Leave Table
Foreign Key
Figure 16
Entity-Relationship diagram
Employee Tables
Emp_code
Leave Tables
Emp_codeTakes Leave
MS-Access
-
8/7/2019 An Overview of Database Management System
33/152
Training Division, NIC, New Delhi 33
Types of Relationship
1. A one-to-many relationship :
It is the most common type of relationship. In a one-to-many relationship, a record in
the first table can have many matching records in the second table, but a record in the
second table has only one matching record in the first table.
2. A many-to-many relationship
In a many-to-many relationship, a record in the first table can have many matching
records in the second table, and a record in the second table can have many matching
records in the first table. 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 from both the tables, first and second. A many-to-many relationship is actually
defining two one-to-many relationships with a third table. For example, the Leave
table and the Training table have a many-to-many relationship thats defined by
creating two, one-to-many relationships to the Employee table.
3. A one-to-one relationship
In a one-to-one relationship, each record in the first table can have only one matching
record in the second table, and each record in the second table can have only one
matching record in the first table. This type of relationship is not common, because
most of the 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.
E Creating New Relationships
Close any tables you have opened since relationships cant be created or modified
between open tables.
ClickTools>>Relationships. Blank screen will appear.
MS-Access
-
8/7/2019 An Overview of Database Management System
34/152
Training Division, NIC, New Delhi34
ClickRelationships>>Show Table. Following Show Table dialog box will
appear as shown in Figure 17.
Figure 17
Select Employee table. ClickAdd.
Select Leave table. ClickAdd.
Similarly you can add more tables depending upon the requirement.
ClickClose. Tables selected will appear as shown in Figure 18.
Figure 18
Drag the Emp_code ofEmployee table over Emp_code ofLeave table to relatethem. Edit Relationships dialog box will appear as shown in Figure 19.
MS-Access
-
8/7/2019 An Overview of Database Management System
35/152
Training Division, NIC, New Delhi 35
Figure 19
ClickCreate. A line joining the two tables will appear as shown in Figure 20.
Figure 20
The above two steps can be repeated for each pair of tables you want to relate.
Close the Relationships window. The system will prompt for the Saving of
Relationship.
ClickYes.
Note: If you drag a field that isnt a primary key and doesnt have a unique index to
another field that isnt a primary key and doesnt have a unique index, an indeterminate
relationship is created.
MS-Access
-
8/7/2019 An Overview of Database Management System
36/152
Training Division, NIC, New Delhi36
EEditing the Existing Relationship
ClickTools>>Relationships. Double click on the middle of the relationship line. Edit Relationship dialog box
will appear as shown in Figure 21.
Figure 21
Defining the join type for a relationship between two tables
Click the Join Type. button, and then click the desired join type from the JoinProperties dialog box as shown in Figure 22.
MS-Access
-
8/7/2019 An Overview of Database Management System
37/152
Training Division, NIC, New Delhi 37
Figure 22
ClickOK.
Deleting Relationship
ClickTools>>Relationships.
Click on the Relationship line to be deleted.
Press Delete key.
Removing Table from the Relationship Window
ClickTools>>Relationships.
Click on the table to be deleted.
Press Delete key.
MS-Access
-
8/7/2019 An Overview of Database Management System
38/152
Training Division, NIC, New Delhi38
Referential Integrity
Referential integrity is a system of rules that Microsoft Access uses to ensure thatrelationships between records in related tables are valid, and that you dont accidentally
delete or change related data.
Basic requirement for setting up referential integrity:1. The matching field from the primary table is a primary key or has a unique
index.
2. The related fields have the same data type.3. Both tables belong to the same Microsoft Access database.
When referential integrity is enforced, you must observe the following rules:
1. You cant enter a value in the foreign key field of the related table that doesnt
exist in the primary key of the primary table.
2. You cant delete a record from a primary table if matching records exist in a
related table. For example, you cant delete an employee record from theEmployees table if there are leave details for that employee in the Leave Table.
If at all it is required to delete a record in Employee table, one should just delete
the corresponding leave details from the Leave table.
3. You cant change a primary key value in the primary table, if that record has
related records.
Setting Referential Integrity Open the relationship in edit mode as already discussed in Editing the Existing
Relationship section.
Select the Enforce Referential Integrity check box.
If referential integrity is enforced and you break one of the rules with related tables,
Microsoft Access displays a message and doesnt allow the change.
Restrictions can be overridden against deleting or changing related records and
preserving referential integrity by setting the Cascade Update Related Fields5 and
Cascade Delete Related Records6 check boxes.
5 Changing a primary key value in the primary table automatically updates the matching value in all
related records.
6 Deleting a record in the primary table deletes any related records in the related table.
MS-Access
-
8/7/2019 An Overview of Database Management System
39/152
Training Division, NIC, New Delhi 39
q Query
A query is logical view of selected data elements from tables as per the specific needs
of the user (which is called subschema). Query option is used for the purpose of display,
updating or analysis of data.
E Simple Query
Select Queries tab from the database window.
Click on New button as shown in Figure 3 of table design. The dialog box for
new query will appear as shown in Figure 23.
Select Design View.
Click on OK.
The Show Table dialog box lets you select the tables/queries/both for creating a query.
Select the table Employee. Click on Add. The field list appears next to the Show Table dialog box as shown
in Figure 24.
Figure 23
MS-Access
-
8/7/2019 An Overview of Database Management System
40/152
Training Division, NIC, New Delhi40
Figure 24
In Show Table dialog box, click on Close button.
Double Click on fields Emp_code, eName, Designation, Salary in the field list.
They may appear in the lower part of the screen as shown in Figure 25.
Save the query as Employee_query.
Select Query>>Run from the menu bar to see the output. Close the Select Query window.
Figure 25
Note: From the database window also the query can be run. Click on Queries tab,
choose the query as Employee_query and click on Open button.
-
8/7/2019 An Overview of Database Management System
41/152
-
8/7/2019 An Overview of Database Management System
42/152
-
8/7/2019 An Overview of Database Management System
43/152
MS-Access
-
8/7/2019 An Overview of Database Management System
44/152
Training Division, NIC, New Delhi44
E Action Queries
An action query is a query that makes changes to many records in just one operation.
The action queries are of four types: delete, update, make-table, and append queries
Delete Query
Delete Query deletes a group of records from one or more tables. With delete queries,
always entire records will be deleted, not just selected fields within records. Single
delete query is used to delete records from a single table or from multiple tables, if
relation has been set between the tables, in a one-to-one relationship or a one-to-many
relationship.
Select Query>>New>>Design View from Database dialog box.
Add tables Employeeand click the Close button.
Select Query>>Delete Query, from the Menu bar.
Drag the asterisk(*) from the field list for the table, from which records are to bedeleted, to the query design grid.
From appears in the Delete cell under this field.
Add field and table to the design grid for which criteria for deleting records has to
be specified. Where appears in the Delete cell under this field. In the Criteriacell for the fields, criteria has to be typed as shown in the Figure 30.
MS-Access
-
8/7/2019 An Overview of Database Management System
45/152
Training Division, NIC, New Delhi 45
Note:IfDelete Query is used for One-to-many relations, records will be deleted
from all the related tables. For example, tables Employee and Leave are having one-
to-many relationship (select the Cascade delete related records option while settingthe relationship.)
In this case, the Delete Query will delete the records from both the tables related, if
the Salary is less than 9500.
To see a list of the records going to be deleted, clickView >>Datasheet view. To
return to query Design view, clickView >>Design View.
ClickQuery>>Run to delete the records permanently from the tables.
Figure 30
MS-Access
-
8/7/2019 An Overview of Database Management System
46/152
Training Division, NIC, New Delhi46
Update Query
qqqqq Change records as a group using an update query
Create an update query, selecting the tables or queries that include the records
you want to update and the fields you want to use for setting criteria.
In query Design view, click the Query>>Update Query.
Drag from the field list to the query design grid the fields you want to update or
you want to specify criteria for.
In the Criteria cell, specify the criteria if necessary.
In the Update To cell for the fields you want to update, type the expression or
value you want to use to change the fields, as shown in Figure 31.
Figure 31
To see a list of the records that will be updated, clickView >>Datasheet View.
This list wont show the new values. To return to query Design view, click
View >> Design View.
ClickQuery>>Run to make the table updated.
-
8/7/2019 An Overview of Database Management System
47/152
MS-Access
-
8/7/2019 An Overview of Database Management System
48/152
Training Division, NIC, New Delhi48
Make-table Query
Create a query, selecting the tables or queries that contain the records you want
to put in the new table.
In query Design view, clickQuery >> Make-Table query. The Make Table
dialog box appears.
In the Table Name box, enter the name of the table you want to create or replace.
For example, to create new table employee_new, type that name in the Table
Name box.
ClickCurrent Database to put the new table in the currently open database. Or
clickAnother Database if you want to create table in a new database and type
the name of the database you want to put the new table in. Type the path if
necessary.
ClickOK.
Drag from the field list to the query design grid the fields you want in the newtable.
In the Criteria cell for the fields that youve dragged to the grid, type the criteria
as shown in Figure 33.
Figure 33
MS-Access
-
8/7/2019 An Overview of Database Management System
49/152
Training Division, NIC, New Delhi 49
For the preview the new table before you actually create it, click the View>>
datasheet view. Return to query Design view by clicking View>>Design View. To create a new table, clickQuery>>Run. It will copy all the fields shown in
Figure 33 and its data to the newly created table employee_new.
Append Query
This query is used to append records from one table to another table using an appendquery.
Create a query that contains the table whose records you want to append to another
table (can be done using Simple Query Wizard option).
Open the query created in the above step in design mode.
ClickQuery>>Append Query. The Append dialog box appears as shown in
Figure 34.
Figure 34
In the Table Name box, enter the name of the table you want to append recordsto.
ClickCurrent Database if the table is in the currently open database. Or click
Another Database and type the name of the database where the table is stored.
Type the path if necessary.
ClickOK.
MS-Access
-
8/7/2019 An Overview of Database Management System
50/152
Training Division, NIC, New Delhi50
If all the fields in both tables have the same names, you can just drag the asterisk
(*) to the query design grid. However, if youre working in a database replica,
youll need to add all the fields instead.
If the fields youve selected have the same name in both tables, Microsoft Access
automatically fills the matching name in the Append To row. If the fields in the
two tables dont have the same name, in the Append To row, enter the names of
the fields in the table youre appending to.
In the Criteria cell for the fields that you have dragged to the grid, type the
criteria on which additions will be made.
In Append To option, select the Field name of the table where the data has to be
appended and in Criteria cell for appending the field value as shown inFigure 35.
Figure 35
ClickQuery>>Run to execute the query.
Note : So far, the practice for basics of Queries has been done. For further details, you
may continue through the following pages, else go to the Section on Forms on Page 59.
MS-Access
-
8/7/2019 An Overview of Database Management System
51/152
Training Division, NIC, New Delhi 51
Figure 36
E More about Queries
Cross-tab Query
Cross-tab queries let you cross-tabulate data in a row-by-column fashion. The example
shown below answers the question Who took how many leaves of what type ?.
ClickNew>>Design View>>OK.
ClickQuery>>Cross-tab query.
Add table Leave to be worked upon as shown in Figure 36.
Note : To quickly create Cross-tab query of data in a single table, Crosstab query
Wizard can be used.
In the design grid of query, specify which fields values become column headings,which fields values become row headings, and the summary values and how you want
to summarize the value (for example, sum, average, count, or otherwise calculate).
Steps for creating Cross-tab query are as follows:
Choose Row Heading in the Crosstab cell for the field you want to use for row
heading. More than one field can be designated, but at least one field must be
Group By in its Total Cell as shown in Figure 37. Expressions can also be used to
group the value together.
MS-Access
-
8/7/2019 An Overview of Database Management System
52/152
Training Division, NIC, New Delhi52
Choose Column Heading in the Crosstab cell for the field you want to use for
column heading. Only one field is allowed and it must contain Group By in itsTotal Cell as shown in Figure 37. Expressions can also be used to group the value
together.
Choose the summary value in the Crosstab cell for the field you want to summarise.
In the Total Cell, choose the summary (usually it is Sum or Average). Dont
choose Group By for this field.
Other fields can also be chosen in Crosstab cell, you want to group by, withoutdisplaying them in result.
ClickView>>Datasheet View to view the result.
For the setting in design grid of query, result is shown in Figure 37.
These settings will
display the fields value
as Row headings
These settings will
Display the fields
value as a Column
heading.
These settings
display the total
of leaves.
Figure 37
-
8/7/2019 An Overview of Database Management System
53/152
MS-Access
i i d i d h SQ i b l
-
8/7/2019 An Overview of Database Management System
54/152
Training Division, NIC, New Delhi54
A Union Query window is opened. Type the SQL statement given below:
SELECT [EMPCODE],[ATTENDENCE] FROM MINIS1 WHERE MONTH=JANUARYUNION SELECT [EMPCODE], [ATTENDENCE] FROM MINIS2 WHEREMONTH=JANUARY;
ClickQuery>>Run.
The output will be as shown in Figure 39.
qqqqq Pass-through Query
This type of query sends commands directly to ODBC databases, such as Microsoft
SQL Server, using commands that are accepted by the server. For example, pass-through
query can be used to retrieve records or change data.
qqqqq Data-definition Query
This type of query creates or alters database objects, such as Microsoft Access or
Microsoft SQL Server tables.
Figure 39
-
8/7/2019 An Overview of Database Management System
55/152
MS-Access
-
8/7/2019 An Overview of Database Management System
56/152
Training Division, NIC, New Delhi56
Figure 41
In the example shown in Figure 41, two tables Employee and Leave are used with the
relationship set on the field emp_code. In this Query, Emp_code and Name from
Employee table and duration from Leave table is selected where the emp_code of both
the tables are equal.
ClickQuery>>Run. The output will be as shown in Figure 42.
E Accessing Query through Form
To access query through form, first create a form having the fields on which the criteriais to be set in the query and then create a button to run the query.
For example, we want to display all the employees details having the same designation.
To do this, first create Form having combo box and a button as shown in Figure 43.
Figure 42
-
8/7/2019 An Overview of Database Management System
57/152
MS-Access
To get the output
-
8/7/2019 An Overview of Database Management System
58/152
Training Division, NIC, New Delhi58
To get the output
Run the form and enter the value for designation and click button Run Query.
Output will be displayed as shown in Figure 45.
Figure 45
MS-Access
q Forms
-
8/7/2019 An Overview of Database Management System
59/152
Training Division, NIC, New Delhi 59
q Forms
A form is a graphical user interface, which can be customized as per user requirements
and is used for the following purposes:
Forms for data-entry in one or more than one table.
User interface forms to set links to various actions to be performed on the
application, for example, Switchboard.
To create custom dialog box to accept user input, and then carry out an actionbased on that input.
E Creating a Form using Wizard
Select Forms tab from the database window.
As in the case of tables and queries, for forms also there are three option buttons-
Open, Design and New. To create a new form, clickNew>>Form wizard>>OK
or
Double Click on Create form by using wizard. The dialog box shown in
Figure 46 appears.
Figure 46
MS-Access
Select the table Employee from the Table/Query7 listbox.
-
8/7/2019 An Overview of Database Management System
60/152
Training Division, NIC, New Delhi60
Select the table Employee from the Table/Query listbox.
Select the fields to be displayed on the form. ClickNext.
Select the layout and style of the form in the next two steps.
Type the title of the form as Employeeand clickFinish.
The form will be opened in the Form View mode as shown in Figure 47.
7 A form can take the data from table or query for viewing and editing purpose.
Figure 47
Close the form.
Note : Modification in the form can be done in the Design view of the form. To go in
design view of form, clickView>>Design View.
MS-Access
E Creating a Form in Design View
-
8/7/2019 An Overview of Database Management System
61/152
Training Division, NIC, New Delhi 61
Creating a Form in Design View
In the Database window, click the Forms tab.
ClickNew.
In the New Form dialog box, clickDesign View. Select the name of the table or query that includes the data you want to base your
form on.
Note : If the form wont contain data (for example, if you want to create a form to
use as a switchboard to open other forms or reports, or if you want to create a custom
dialog box), dont select any Table or Query from this list.
ClickOK. Form will appear as shown in Figure 48.
Figure 48
Select View>>Field List.
This will give the field list as shown in Figure 49. The required fields can be dragged on
to the form. Form will appear as shown in Figure 49.
Save the form and give it a name, say, empform.
Close the form.
-
8/7/2019 An Overview of Database Management System
62/152
MS-Access
E Different Controls
-
8/7/2019 An Overview of Database Management System
63/152
Training Division, NIC, New Delhi 63
In a form, we can also introduce many controls. Various controls (like label, textbox,
combobox, command button, tab etc.) available on the tool bar as shown in Figure 51,
can be put on the form.
Figure 51
Label
Label on a form or report is used to display descriptive text such as titles, captions, or
brief instructions. Labels do not display values from fields or expressions; theyre always
unbound and they dont change as you move from record to record.
Open a form in Design view
Click the Label tool in the toolbox.
On the form, click where you want to place the label, and drag the mouse.
In the label drawn, type the text for the label.
Text boxes
Text boxes are drawn on a form or report to display data from a table, query, or SQL
statement. This type of text box is called a bound text box because its bound to data ina field. Text boxes can also be unbound8 . For example, you can create an unbound text
box (i.e. text box isnt bound to the data in field) to display the results of a calculation,
or to accept input from a user.
8 Data in an unbound text box isnt stored in field of table.
MS-Access
Create a bound Text box
-
8/7/2019 An Overview of Database Management System
64/152
Training Division, NIC, New Delhi64
Create a Text box for computed Fields (for numeric and text entries)
Open a form in Design view and select a table from the New form dialog box
Click the textboxtool in the toolbox. Click on the form where the control has tobe placed and do the following:-
Note: A text box is the most common type of control used to display a calculated
value, but you can use any control that has a Control Source property.
Type the expression in the Control Source property of the textbox. For example,
for the calculation ofDA, type expression = [salary] * 0.43in the Text box.
Note: To use the Expression Builder to create the expression, clickView>>Properties
to open the controls property sheet, and then type the expression in the Control
Source property box or click the Build button to open the Expression Builder.
Create a command button with a wizard
Open a form in Design view.
Click the Control Wizards tool in the toolbox if its not already pressed in.
In the toolbox, click the Command Button tool.
On the form, click where you want to place the command button. The wizard
dialog box will be opened as shown in Figure 52.
Open a form in Design view. ClickView>>Field List. Drag the field(s) from the field list and position them on
the form.
Create an unbound Text box
Click the Text Box Tool in the toolbox.
Click anywhere on the form to create a default-sized text box, or drag to create atext box thats the size you want.
-
8/7/2019 An Overview of Database Management System
65/152
MS-Access
Create a List Box or combo box
-
8/7/2019 An Overview of Database Management System
66/152
Training Division, NIC, New Delhi66
If data type of field is Lookup fieldin table
Create a Lookup field in table Design view by selecting Lookup Wizard asDataType and follow the directions in the wizard dialog boxes and create a new
form based on a that table. In form Design view, clickview>>Field List and then drag the Lookup field
from the field list to the form. Microsoft Access automatically creates the lookup
list box or combo box.
OR
Ifdata type of field is not a Lookup fieldin table .
Open the form in Design view.
In the toolbox, click the ListBox or ComboxBox and then click on theform where these controls have to be placed and follow the directions in the Wizard
dialog boxes.
Switch to Form view to test the list box or combo box. It will appear as shown in
Figure 54.
Figure 54
List box or combo box is quicker and easier way to select a value from a list than to
remember a value to type. The list in a list box consists of rows of data. Rows can have
one or more columns, which can appear with or without headings.
MS-Access
To remove navigation bar from the view of form
-
8/7/2019 An Overview of Database Management System
67/152
Training Division, NIC, New Delhi 67
At the button of each form, we generally have a navigation bar which is used to
display the record no. A navigation bar is shown in Figure 55.
Figure 56
Click here to
open formproperty
dialog box.
In the form properties, select Navigation Button option to NO. The view of the
form will appear without navigation bar at the bottom
Figure 55
The steps to remove the navigation bar from the view of the form, are as follows:
Open the form properties by right clicking the mouse button by placing the cursor
at left most corner of the form in design view as indicated by arrow. It will appear
as shown in Figure 56.
-
8/7/2019 An Overview of Database Management System
68/152
MS-Access
E Further Enhancements in Form Design
-
8/7/2019 An Overview of Database Management System
69/152
Training Division, NIC, New Delhi 69
Figure 58
Note: To change the name of a Page tab, double-click the page (Page1 or Page2) to
open its property sheet, and then specify a new name in the Caption property. If youdont specify a name in the Caption property, Microsoft Access uses the setting in
the Name property.
To add, delete, or change the order of tabs, click the border of the tab control with
the right mouse button and clickInsert Page, Delete Page, or Page Order.
Adding pictures, graphs and sound to a Form
To add a picture or chart to the form, select Insert>>Picture or Insert>>Chart.
Choose the picture from the available ones or make one of your own.
Select Insert>>Object to add Excel Sheet, Chart, bitmaps, presentation, etc. to
the form.
Form with multiple pages using tabs
Open a form in Design view.
In the toolbox, click the Tab Control tool and then click on the form where
the control has to be placed. Microsoft Access adds a tab control with two pages.
The first page is on top.
ClickField List on the toolbar to display the field list and drag one or more fields
to the tab page by selecting option Page1 or Page2. Form will appear as shown in
Figure 58.
MS-Access
Create a new object by selecting Create New or use the already existing object
b l ti C t f Fil ti
-
8/7/2019 An Overview of Database Management System
70/152
Training Division, NIC, New Delhi70
by selecting Create from File option. Check the Display As Icon option
In the Objecttype dialog box, select Sound.
Select OK.
To view selected records through a form
In a view of form or subform or datasheet, select the entire contents of that field
on which filters results is based.
Select the value in form view or database view (as shown in figure, the
Designation value SSA is selected for filter) and then clickFilter By Selectionon the toolbar. The output of the form will appear as shown in Figure 59.
Figure 59
MS-Access
Adding page Numbers and Date
O h f i D i i
-
8/7/2019 An Overview of Database Management System
71/152
Training Division, NIC, New Delhi 71
Open the form in Design view.
ClickInsert >> Page Numbers or Insert >> Date And Time. In the Page Numbers dialog box, select the format, position, and alignment for
the page number.
To include a date, select the Include Date check box, and then click a date format.
To create a hyperlink in the form
Hyperlinks can be used in forms and datasheets to jump to objects in the same or another
Microsoft Access database, to documents created with Microsoft Word, Microsoft Excel,
and Microsoft PowerPoint, and to documents on the global Internet or on a local
intranet.
The hyperlinks can be created on a form in different ways.
Create a field to store hyperlinks that will change for each record
Open an existing table in Design view or create a new table.
Type a field name for the field used to store the hyperlinks.
In the Data Type column for that field, select Hyperlink. Save and close the design of the table.
The table in design view is shown in Figure 60.
Figure 60
MS-Access
Open the table in Datasheet View to enter data.
In E mail field Click Insert>> Hyperlink In the insert hyperlink dialog box
-
8/7/2019 An Overview of Database Management System
72/152
Training Division, NIC, New Delhi72
In E_mail field, ClickInsert>> Hyperlink. In the insert hyperlink dialog box,select the appropriate tab for Link to and fill all the details. Figure 61 shows the
details ofLink to: E-mail Address
Figure 61
Note :The hyperlink can be followed from the datasheet view of the form.
-
8/7/2019 An Overview of Database Management System
73/152
MS-Access
Charts and ActiveX Controls
Add a new chart to a form
-
8/7/2019 An Overview of Database Management System
74/152
Training Division, NIC, New Delhi74
Add an ActiveX control (OLE custom control) to a form
Open a form in Design view.
Click the More Controls tool in the toolbox.
Click the control you want in the list.
On the form, click where you want to place the control.
Right-click the control, and then clickProperties to open the ActiveX control
property sheet. Set the necessary properties.
Add a new chart to a form
Open the form in Design view.
Click on Insert >>Chart.
On the form, click where you want to place the chart.
Follow the directions in the Chart Wizard, which creates the chart based on
available tables or queries and the fields you select.
Creating Sections
The effectiveness of a form can be increased by adding one or more sections. Most
forms have just a detail section, but a form can also include form header, page header,
page footer, and form footer sections.
To insert Form Header/Footer And Page Header/Footer
ClickView>> Form Header/Footer or ClickView>> Page Header/Footer
Give the appropriate title to the form in the Form Header section as shown inFigure 62.
MS-Access
-
8/7/2019 An Overview of Database Management System
75/152
Training Division, NIC, New Delhi 75
Figure 62
MS-Access
q Reports
A report is an effective way to present data in a required printed format because of
-
8/7/2019 An Overview of Database Management System
76/152
Training Division, NIC, New Delhi76
A report is an effective way to present data in a required printed format because of
control over the size and appearance of objects on a report. Most of the information in a
report comes from an underlying table, query, or SQL statement, which is the source of
the reports data. Other information in the report is stored in the reports design.
E Creating a Report using Wizard Select Reports tab from the database window.
Select New.
The New Report dialog box appears as shown in Figure 63.
Figure 63
MS-Access
Access gives various options for report creation. Report Wizard automatically creates a
report based on the selected fields of the table/query selected.
-
8/7/2019 An Overview of Database Management System
77/152
Training Division, NIC, New Delhi 77
Click on Report Wizard.
Select the table Employee on which the report is to be generated.
The report picks up the name of the table to be taken as the title of the report.
ClickOK. Select the fields NAME, Date_of_birth, DESIGNATION, Salary from the list of
available fields as shown in Figure 64.
Figure 64
Select the fields by pressing .
Click on Next. Next screen will appears as shown in Figure 65.
-
8/7/2019 An Overview of Database Management System
78/152
MS-Access
If sort order of records is not required, click on Next and you get the screen to
decide the layout of the report as shown in Figure 67.
-
8/7/2019 An Overview of Database Management System
79/152
Training Division, NIC, New Delhi 79
Figure 67
Select the Report layout as Tabular and orientation as Portrait or Landscape. Click on Next, and you will get the screen as shown in Figure 68.
Figure 68
MS-Access
Select the Style for your report and clickNext.
Give title for your report as Employee and selectoption Preview the report and
then select Finish as shown in Figure 69.
-
8/7/2019 An Overview of Database Management System
80/152
Training Division, NIC, New Delhi80
Figure 69
Clicking on Finish, shows the Preview of the Report as shown in Figure 70 and
the report file will be saved with same name as the title of report which can be
changed.
Figure 70
Report created using wizard option can be modified as and when required by going in
design view of that report.
MS-Access
E Creating a Report in Design View
In the Database window, select Reports object.
-
8/7/2019 An Overview of Database Management System
81/152
Training Division, NIC, New Delhi 81
In the Database window, select Reports object.
Click on New.
In the New Report dialog box, clickDesign View.
Select the name of the table or query and ClickOK. For example, select table
employee , that contains the data you want to base your report on. (If you want an
unbound report, dont select anything from this list.) Click on View>>Field list (if the field list is not visible) and drag the required
fields of the table in the detail section of report design view.
Label for the fields should be written in page header and title for the report should
be written in the report header.
Page Header/Footer and Report Header/Footer options are selected by
clicking View>>Page Header/Footer and View>>Report Header/Footer asshown in Figure 71.
Figure 71
ClickView>> Print Preview to get preview of the report as shown in Figure 72.
MS-Access
-
8/7/2019 An Overview of Database Management System
82/152
Training Division, NIC, New Delhi82
Figure 72
E Creating a Report for Mailing Labels
This type of report is used to create labels from the database which can be used for the
mailing purpose.
In the Reports tab ofDatabase window, clickNew.
In the New Report dialog box, clickLabel Wizard. Select the table or query that contains the data for the labels, and then clickOK.
Follow the instructions in the wizard dialog boxes. The output of this report will
be as shown in Figure 73.
MS-Access
-
8/7/2019 An Overview of Database Management System
83/152
Training Division, NIC, New Delhi 83
Figure 73
E Creating Calculated fields in the Report
The calculated fields can be displayed on a report to show the results based on some
calculations on a field.
To include a calculated field, create a text box in the Detail section of the report
in the design view.
Write the expression for calculation in the Text box. Results would be displayedin Print Preview
For example, if we have to calculate DA from the Basic of the employee, the expres-
sion in the text boxes for DA will be =[basic]*0.42
E Sorting and Grouping Records
Sort records in a reportRecords in a report can be arranged in certain order depending on the sorting and grouping
order defined. A report can be sorted on upto a maximum of 10 fields or expressions.
MS-Access
To create report in the sorted form, do the following steps:
Open the report in Design view.
Click on View>>Sorting And Grouping to display the Sorting And Grouping
box as shown in Figure 74
-
8/7/2019 An Overview of Database Management System
84/152
Training Division, NIC, New Delhi84
Figure 74
The field or expression in the first row is the first sorting level (the largest set). The
second row is the second sorting level, and so on upto 10 sorting levels can be defined.
For each sorting level, sort order can be defined as Ascending or Descending.
Click the field or expression whose group properties you want to set.
Set the group properties in the following list.
For each field defined in the sorting order, group properties can be defined.
Either Group Header or Group Footer should be set to Yes in order to create
a group level.
GroupHeader. Adds or removes a group header for the field or expression.
GroupFooter. Adds or removes a group footer for the field or expression.
box as shown in Figure 74.
In the first row of the Field/Expression column, select a field name, or type an
expression as shown in Figure 74.
MS-Access
GroupOn. Specifies the value or range of values that starts a new group. The
options you see depend on the data type of the field on which youre grouping. If
you group on an expression, you see all the options for all data types.
GroupInterval Specifies any interval that is valid for the values in the field or
-
8/7/2019 An Overview of Database Management System
85/152
Training Division, NIC, New Delhi 85
GroupInterval. Specifies any interval that is valid for the values in the field or
expression youre grouping on.
Keep Together. Keeps groups together on one page.
Set the group properties as shown in Figure 75.
Figure 75
The design view of the form will be appear as shown in Figure 76.
Figure 76
MS-Access
Note: When designing a report, the field on which grouping is to be done should be
kept in Group Header section not in Detail section as Designation field is kept inDesignation header section.
-
8/7/2019 An Overview of Database Management System
86/152
Training Division, NIC, New Delhi86
The output will be appear as shown in Figure 77.
Figure 77
E Calculating a Running Sum
Running Sum property is used to calculate record-by-record or group-by-group totals
in a report. The RunningSum property applies only to a text box and in the Design
View of the report.
Note : To open text box property sheet, first select the text box and click the right
mouse button, select Properties from the option.
MS-Access
To calculate running sum in a report
Open report in Design View.
Create Text Box in the Report Footer
-
8/7/2019 An Overview of Database Management System
87/152
Training Division, NIC, New Delhi 87
Create Text Box in the Report Footer. Type Expression in the Text Box created at the Report Footer. For example, to
calculate total salary given, type an expression : = Sum ( [Salary]) in Report Footer
as shown in Figure 78.
Figure 78
Note: Expression for the running sum can be given for more than one field in report
footer.
The output of this report will appear as shown in Figure 79.
MS-Access
-
8/7/2019 An Overview of Database Management System
88/152
Training Division, NIC, New Delhi88
Figure 79
Note: If calculation is to be made on Groups, the expression must be written in the
Group footer.
To include Serial No. in Report
Open report in Design View.
Create text box in Detail Section of report to calculate a record-by-record total.
From the property sheet, click on either Data or All tab.
Set ControlSource Property =1 and set the RunningSum property to Over Group.
The Design View of the report appears as shown in Figure 80.
MS-Access
-
8/7/2019 An Overview of Database Management System
89/152
Training Division, NIC, New Delhi 89
Figure 80
The output for this design view appears as shown in Figure 81.
Figure 81
Save this report as employee_detail.
Note: To give S.NO. groupwise, place the text box in a group header and in the
Text box property sheet, set RunningSum as OverGroup and ControlSource
Property= 1.
MS-Access
E Different Types of Reports
Multiple Column Report
-
8/7/2019 An Overview of Database Management System
90/152
Training Division, NIC, New Delhi90
A multiple-column report can be used to print the report in more than one column. In
this case Report Header/Footer and Page Header/Footer span the full width of the
report, while Group Header/Footer and Detail Section span the width of one column.
For example, if you want to print the data in two three-inch columns, place the controls
within the width of one column; in other words, place the controls in the first three
inches of these sections in Design view.
Create a report and open it in Design View. On the File menu, clickPage Setup.
In the Page Setup dialog box, click the Columns tab. Under Grid Settings, in the Number Of Columns box, type the number of
columns you want on each page.
In the Row Spacing box, type the amount of vertical space you want betweeneach record in the detail section.
Note : If you left space between the last control in the detail section and the bottomedge of the detail section, you can leave Row Spacing set to 0.
In the Column Spacing box, type the amount of space you want between the
columns.
Under Column Size, type the width you want for a column in the Width box; for
example, 3. You can set the height of the detail section by typing a number in theHeight box or by adjusting the height of the section in Design view.
Under Column Layout, click suitable option as shown in Figure 82.
Click the Page tab of the Page Set-up dialog box
Under Orientation, clickPortrait or Landscape.
ClickOK.
MS-Access
-
8/7/2019 An Overview of Database Management System
91/152
Training Division, NIC, New Delhi 91
Figure 82
Print preview of the Report is shown in Figure 83.
Figure 83
MS-Access
Crosstab Report
Cross-tab Report is based on a Cross-tab query meant for analysing the data in a
cross-tab format.
-
8/7/2019 An Overview of Database Management System
92/152
Training Division, NIC, New Delhi92
Create a Crosstab query.
In query Design View, display the querys property sheet by double-clicking
anywhere outside the design grid and outside the field lists.
In the ColumnHeadings property box, type the column headings you want toappear in the report, separating each one with a semicolon. If a column heading
contains spaces, enclose it in double ( ) quotation marks. For instance, in a
query showing sales by quarter, you would type:CL Taken;El Taken;Medical Taken
Create a blank report that is bound to the crosstab query.
Add the controls for the fields you want to appear in the report.
Place labels for the row headings and column headings in the page header. Place text boxes for the row headings and column values in the detail section.
The report thus obtained is shown in Figure 84.
Figure 84
MS-Access
q Switchboard and Custom Menus
After creating the forms, reports etc. in the database, one needs to create a GUI menu(Graphics User Interface menu). It will helps in navigating among the various objects
like forms reports macros modules in the database Various objects can be opened by
-
8/7/2019 An Overview of Database Management System
93/152
Training Division, NIC, New Delhi 93
like forms, reports, macros, modules in the database. Various objects can be opened by
clicking the various buttons on the Switchboard.
E Creating a Single Page Switchboard
Open the database containing forms, reports or other objects already created.
ClickTools >>Database Utilities >> Switchboard Manager.
If switchboard is created for the first time then Microsoft Access asks if youd like tocreate a switchboard,
ClickYes. The following dialog box will appear as shown in Figure 85.
Figure 85
Following options are available in Switchboard Manager:
Close To close switchboard Manager.
New To add new switchboard Page to Switchboard manager.
Edit To add items to switchboard page.
Delete - To delete switchboard Page.
Make Default When switchboard manager has more than one page, make the main
switchboard page default that will open first when switchboard is run.
MS-Access
ClickEdit button of Switchboard page (shown in Figure 85) to create all the
switchboard items of that page. The dialog box appeared as shown in Figure 86.
-
8/7/2019 An Overview of Database Management System
94/152
Training Division, NIC, New Delhi94
Figure 86
ClickNew button to add switchboard items to this page. The dialog box appearsas shown in Figure 87.
Figure 87
In the Edit Switchboard Item dialog box, in the Text: field, type the text that is
to be displayed for the Switchboard Item on the Switchboard page.
Select the Command: to be executed.
Depending on the selection of command, the next field of the dialog box changes.
Enter the values as shown in Figure 88.
-
8/7/2019 An Overview of Database Management System
95/152
MS-Access
Once the Switchboard is made, one form named Switchboard and a table named
Switchboard items will appear in the database window in their respective objects.
The Switchboard page for the above items will be appeared as shown in Figure 89.
-
8/7/2019 An Overview of Database Management System
96/152
Training Division, NIC, New Delhi96
Figure 89
Switchboard Page
Switchboard
Page Items
Running the Switchboard
Click on Forms object in the database window.
Select Switchboard form.
Click on Open. Default Main Switchboard page will opened as shown inFigure 89.
MS-Access
E Creating a Multiple Page Switchboard
Note: If more than one switchboard pages is required, then first create all the pages in
the Switchboard Manager dialog box.
-
8/7/2019 An Overview of Database Management System
97/152
Training Division, NIC, New Delhi 97
ClickTools >>Database Utilities >> Switchboard Manager.
If switchboard is created for the first time then Microsoft Access asks if youd like to
create a switchboard.
ClickYes. The Switchboard Manager dialog box appears as shown in Figure 85.
ClickNew in the Switchboard Manager Dialog box to add new page, the dialog
box appeared as shown in Figure 90.
Figure 90
Type the Name of the New Switchboard Page.
ClickOK.
A new page is added to the Switchboard manager.
Similarly, add all the Switchboard Pages to Switchboard Manager by clicking
New button. The Switchboard Manager dialog box with all pages included will
appear as shown in Figure 91.
MS-Access
-
8/7/2019 An Overview of Database Management System
98/152
Training Division, NIC, New Delhi98
Figure 91
Figure 92
To add items to the switchboard page
Select the Switchboard page in which Items has to be added. For example, select
Main Switchboard page.
ClickEdit inthe Switchboard Manager dialog box to edit all the items in that
page. The Edit Switchboard dialog box will appear as shown in Figure 92.
-
8/7/2019 An Overview of Database Management System
99/152
-
8/7/2019 An Overview of Database Management System
100/152
-
8/7/2019 An Overview of Database Management System
101/152
MS-Access
SN SWITCHBOARD SWITCHBOARD COMMANDS OBEJCT TOPAGE PAGE ITEMS BE EXECUTED
1 Main Maintain Goto Switchboard Update
Switchboard Employees Data Employees Detail
E t L O f i L
-
8/7/2019 An Overview of Database Management System
102/152
Training Division, NIC, New Delhi102
Enter Leave Open form in Leave
Details Edit Mode
Year End Run Macro
Processing
Reports Goto Switchboard Reports
Exit Exit Application -
2 Update Add New Open form in Employee
Employees Employee Add Mode
DetailModify Employee Open form in employee
Data edit mode
Delete Employee Run Macro Macro_Delele_
Records emp_Records
Exit Go to switchboard Main Switchboard
3 Report Employee Report Open Report employee
Creating Employee Open Report Labels employee
Labels
Exit Go to Main
Switchboard Switchboard
Table 2 : Switchboard items and their commands in Multiple page Switchboard
-
8/7/2019 An Overview of Database Management System
103/152
-
8/7/2019 An Overview of Database Management System
104/152
-
8/7/2019 An Overview of Database Management System
105/152
-
8/7/2019 An Overview of Database Management System
106/152
MS-Access
E Creating Custom Menus
Open database to which Custom Menu is to be added.
ClickView >> Toolbars>> Customize. Customize dialog box will appear as
shown in Figure 101.
-
8/7/2019 An Overview of Database Management System
107/152
Training Division, NIC, New Delhi 107
Figure 101
ClickToolbars tab (If it is not already active) and choose New. Type Main menu in the text box in New Toolbar dialog box as shown in
Figure 102.
Figure 102
ClickOK.
-
8/7/2019 An Overview of Database Management System
108/152
-
8/7/2019 An Overview of Database Ma