Database Notes
Database Notes
Continuing developments in information technology and its business applications have resulted in the
evolution of several major types of databases. Several major conceptual categories of databases that may
be found in computer-using organizations include:
Operational Databases - These databases store detailed data needed to support the operations of the
entire organization. They are also called subject area databases (SADB), transaction databases, and
production databases. Examples are customer databases, personnel databases, inventory databases,
and other databases containing data generated by business operations.
Distributed Databases - Many organizations replicate and distribute copies or parts of databases to
network servers at a variety of sites. These distributed databases can reside on network servers on the
World Wide Web, on corporate Intranets or extranets, or on other company networks. Distributed
databases may be copies of operational or analytical databases, hypermedia or discussion databases,
or any other type of database. Replication and distribution of databases is done to improve database
performance and security.
2
External Databases - Access to external, privately owned online databases or data banks is available
for a fee to end users and organizations from commercial online services, and with or without charge
from many sources on the Internet, especially the Web.
hypermedia databases on the web: - the rapid growth of web sites on the internet and corporate
intranets and extranets has dramatically increased the use of databases of hypertext and hypermedia
documents. a web site stores such information in a hypermedia database consisting of a home page
and other hyperlinked pages of multimedia or mixed media (text, sound, etc.).
3
units that supplied into the centre as well as the products that got delivered out from the distribution
centre on each day; this is where DBMS comes into picture.
Banking System: For storing customer info, tracking day to day credit and debit transactions, generating
bank statements etc. All this work has been done with the help of Database management systems.
Education sector: Database systems are frequently used in schools and colleges to store and retrieve the
data regarding student details, staff details, course details, exam details, payroll data, attendance details,
fees details etc. There is a hell lot amount of inter-related data that needs to be stored and retrieved in an
efficient manner.
Online shopping: You must be aware of the online shopping websites such as Amazon, Flipkart etc.
These sites store the product information, your addresses and preferences, credit details and provide you
the relevant list of products based on your query. All this involves a Database management system.
System development particularly for the large projects, it is useful to divide the application development
into the several steps. They can be used to track the progress of the development team and highlight the
steps remaining.
Feasibility The feasibility process steps defines project and provides the estimates of the costs.
Analysis During the analysis phases system analysts collect the data definitions, forms and reports from
the users. These are used to design the databases and all of the new forms, report from user.
Design It is most critical process. Database systems and the associated development tools are incredibly
powerful, but databases must be carefully designed to take advantages of the power. Designing the
database and the tables is key step in creating the database application. Forms are defined that transfer
data into database and reports uses , queries to retrieve and display the data needed by the users.
Development During the development stages, the forms, reports and the application feature helps the file
to create.
Implementation Implementation usually consists of transfer of the data, installation, training and review.
Data Independence
This brings us to our next topic: data independence. It is the property of the database which tries to ensure
that if we make any change in any level of schema of the database, the schema immediately above it
would require minimal or no need of change.
Physical Data Independence: This means that for any change made in the physical schema, the need to
change the logical schema is minimal. This is practically easier to achieve. Let us explain with an
example.
4
Logical Data Independence: This means that for any change made in the logical schema, the need to
change the external schema is minimal. As we shall see, this is a little difficult to achieve. Let us explain
with an example.
Features of a DBMS
Data dictionary- Describes files and fields of data. It can be a procedure document or disk files that
stores the data definitions or a description of the structure of data used in the database.
Utilities- DBMS utilities are programs that allow you allow to manntain the database by
creating,editing and deleting data records and files.
Query Language/Data manipulation language- Is an ease-to-use computer language for making
queries to a database and for retrieving selected records based on the particular criteria and format
indicated.
Report Generator- Is a program users may employee to produce on-screen or printed document from
all or part of a database.
Access security- A feature that allows the database administrator to specify different access
previleges for different users of DBMS.
System Recovery- This feature enables a DBA to recover contents of a database in the event of
hardware or software failure.
Data organization in a database
A database organizes information into:
Field: A character or string of characters that represent a data item.
Record: A collection of related fields that represent a single entity.
Table or file: A collection of related records. A table is made up of rows called records and columns
called fields.
Database: A collection of related tables or files
DBMS Interfaces
User-friendly interfaces provided by a DBMS may include the following:
Menu-Based Interfaces for Web Clients or Browsing. These interfaces pre-sent the user with lists of
options (called menus) that lead the user through the formulation of a request. Menus do away with
the need to memorize the specific commands and syntax of a query language; rather, the query is
composed step-by-step by picking options from a menu that is displayed by the system.
5
Forms-Based Interfaces. A forms-based interface displays a form to each user. Users can fill out all of
the form entries to insert new data, or they can fill out only certain entries, in which case the DBMS
will retrieve matching data for the remaining entries. Forms are usually designed and programmed for
naive users as inter-faces to canned transactions.
Graphical User Interfaces. A GUI typically displays a schema to the user in diagrammatic form. The
user then can specify a query by manipulating the diagram. In many cases, GUIs utilize both menus
and forms. Most GUIs use a pointing device, such as a mouse, to select certain parts of the displayed
schema diagram.
Natural Language Interfaces. These interfaces accept requests written in English or some other
language and attempt to understand them. A natural language interface usually has its own schema,
which is similar to the database conceptual schema, as well as a dictionary of important words. The
natural language interface refers to the words in its schema, as well as to the set of standard words in
its dictionary, to interpret the request.
Speech Input and Output. Limited use of speech as an input query and speech as an answer to a
question or result of a request is becoming commonplace. Applications with limited vocabularies
such as inquiries for telephone directory, flight arrival/departure, and credit card account information
are allowing speech for input and output to enable customers to access this information. The speech
input is detected using a library of predefined words and used to set up the parameters that are
supplied to the queries. For output, a similar conversion from text or numbers into speech takes place.
Interfaces for Parametric Users. Parametric users, such as bank tellers, often have a small set of
operations that they must perform repeatedly. For example, a teller is able to use single function keys
to invoke routine and repetitive transactions such as account deposits or withdrawals, or balance
inquiries. Systems analysts and programmers design and implement a special interface for each
known class of naive users. Usually a small set of abbreviated commands is included, with the goal of
minimizing the number of keystrokes required for each request. For example, function keys in a
terminal can be programmed to initiate various commands. This allows the parametric user to proceed
with a minimal number of keystrokes.
Interfaces for the DBA. Most database systems contain privileged commands that can be used only by
the DBA staff. These include commands for creating accounts, setting system parameters, granting
account authorization, changing a schema, and reorganizing the storage structures of a database.
DATABASE MODELS
A Data Model is a logical structure of Database. It describes the design of database to reflect entities,
attributes, relationship among data, constrains etc. The term database model refers to methodology for
storing data. There are several models which include hierarchical, network, relational, object-oriented and
object oriented models.The relationships among the many individual records in databases are based on
6
one of several logical data structures or models. DBMS are designed to provide end users with quick,
easy access to information stored in databases. Five fundamental database structures are:
a) Hierarchical database model
Data items are organized in hierarchical or tree structure. Early mainframe DBMS packages used the
hierarchical structure, in which:
- Records are dependent and arranged in multilevel structures, consisting of one root record and any
number of subordinate levels.
- Relationships among the records are one-to-many, since each data element is related only to one
element above it.
- Data element or record at the highest level of the hierarchy is called the root element.
In this case, to store or retrieve data, system must start at the top. This structure is fast when you’re
looking for the data from the top. The most serious problem starts when we’re looking for data from the
bottom or middle of hierarchy. A single object called the parent acts as the root which other objects
branch out as shown below.
Allows many-to-many relationships among records. That is, the network model can access a data
element by one of several paths, because any data element or record can be related to any number of
other data elements.
- Items in the network model are interconnected, however, physically separated.
- There are 2/more entry points through which the pre-defined items can be searched
- The arrows display possibility of making an efficient connection for searching for data in a
particular module.
- Although this structure solves the hierarchical problems, it is rather costly to develop and
maintain (e.g. at the arrow points, there are indexes of modules –requiring duplication of
7
records that are grouped for search purposes –what requires processing capabilities and huge
amount of storage space. Besides the storage requirement disadvantage, the designer must
know in advance, which questions might be asked of the data.)
- Used by most microcomputer DBMS packages, as well as many minicomputer and mainframe
systems.
- Data elements within the database are stored in the form of simple tables, which are also referred to
as relations. Each table stores attributes in columns that describe specific entities. These sets (tables)
are not physically connected to each other. The connection (relationship) exists through the matching
data in each table. (they are related if they contain common fields.)
- DBMS packages based on the relational model can link data elements from various tables to provide
information to users.
The biggest advantage of this structure is that the designer doesn’t have to know in advance what
questions might be asked of the data. If the data is carefully defined, the DBMS can answer basically any
question.
d) Object-Oriented Model
They can handle new data types including graphics, audio and video which may be combined with text
into multimedia format. Object oriented Database Management System (OODBMS) uses “objects” ,
software written in small, reusable chunks, as elements written database files. An object would consist
8
data in form of multimedia and operations called methods, programs that objects use to process
themselves. Objects interact by sending messages to each other.
Data is organized into logical components called objects. An object is a dynamic entity that has its own
state (data) and behavior (methods).An object is generated from a base structure called a class. These
models are aimed at overcoming the restrictions of normalization rules enforced in a relational model.
The object-oriented structure is rather a new and still evolving structure that defines objects that can be
used by many different programs.
- In an object-oriented structure, an object consists of data values describing the attributes of an entity
plus the operations that can be performed upon the data. This encapsulation capability allows the
object-oriented model to better handle more complex types of data (graphics, voice, text) than other
database structures.
Multimedia web-based applications for the Internet and corporate Intranets and extranets started to
become a major application area for object technology.
Multidimensional Structure:
The multidimensional database model:
- Is a variation of the relational model that uses multidimensional structures to store data and
relationships between data.
- A major benefit of multidimensional databases is that they are a compact and easy-to- understand
way to visualize and manipulate data elements that have many interrelationships.
- Multidimensional databases have become the most popular database structure for the analytical
databases that support online analytical processing (OLAP) applications.
9
Evaluation of Database Model Structures:
Requires knowledge of a
programming language.
Requires knowledge of a
programming language.
Compact and easy to understand Not currently developed
Multidimensional way to visualize and manipulate for broad business
data elements that has many application use.
Structure interrelationships.
10
which fast answers to complex
business queries are required.
Flexible in that it can handle ad Cannot process large
Relational hoc information requests. amounts of business
Structure transactions as quickly
Easy for programmers to work and efficiently as the
with. End users can use this hierarchical and network
model with little effort or models.
training.
Database Languages
As whatever we want to be manipulated by computer has to be written using specific language, database
is not beyond them. To write or create database management system we use database languages. They are
of two types;
Data Definition Language (DDL)
Data Manipulation Language (DML).
DDL is used to design a database and DML is used express database’s queries and updates.
DML (Data Manipulation Language):
A Data Manipulation Language is a database language which enables users to access and modify stored
data in a database. It is a language that provides a set of operations to support the basic data manipulation
11
operations on the data held in the databases. It allows users to insert, update, delete and retrieve data from
the database.
The types of access are as follows,
Retrieval of information stored in the database.
Insertion of new information into the database.
Deletion of information stored in the database.
Modification of information stored in the database.
The part of DML that involves data retrieval is called a query language.
The following table gives an overview about the usage of DML statements in SQL:
The following table gives an overview about the usage of DCL statements in SQL:
DCL is used for granting and revoking user access on a database –
To grant access to user – GRANT
To revoke access from user – REVOKE
12
In practice, the data definition and data manipulation languages are not two separate languages. Instead
they simply form parts of a single database language such as Structured Query Language (SQL). SQL
represents combination of DDL and DML, as well as statements for constraints specification and schema
evaluation.
The requirements and the collection analysis phase produce both data requirements and functional
requirements. The data requirements are used as a source of database design. The data requirements
should be specified in as detailed and complete form as possible. In parallel with specifying the data
requirements, it is useful to specify the known functional requirements of the application. These consist
of user-defined operations that will be applied to the database (retrievals and updates). The functional
requirements are used as a source of application software design. Of course some functions may produce
also needs for database design. Note that some phases are database management system independent and
some are dependent. The idea is to design first the database without thinking about the actual database
system - just to concentrate on the data.
Conceptual Design
Once all the requirements have been collected and analyzed, the next step is to create a conceptual shema
for the database, using a high level conceptual data model. This phase is called conceptual design. The
result of this phase is an Entity-Relationship (ER) diagram or UML class diagram. It is a high-level data
13
model of the specific application area. It describes how different entities (objects, items) are related to
each other. It also describes what attributes (features) each entity has. It includes the definitions of all the
concepts (entities, attributes) of the application area.
During or after the conceptual shema design, the basic data model operations can be used to specify the
high-level user operations identified during the functional analysis. This also serves to confirm that the
conceptual schema meets all the indenfied functional requirements.
Logical Design
The result of the logical design phase (or data model mapping phase) is a set of relation shcemas. The ER
diagram or class diagram is the basis for these relation schemas. To create the relation shemas is quite a
mechanical operation. There are rules how the ER model or class diagram is transferred to relation
shemas. The relation schemas are the basis for table definitions. In this phase (if not done in previous
phase) the primary keys and foreign keys are defined.
Normalization
Normalization is the last part of the logical design. The goal of normalization is to eliminate redundancy
and potential update anomalies. Redundancy means that the same data is saved more than once in a
database. Update anomaly is a consequence of redundancy. If a piece of data is saved in more than one
place, the same data must be updated in more than one place. Normalization is a technique by which one
can modify the relation schema to reduce the redundancy. Each normalization phase adds more relations
(tables) into the database.
Physical Design
The goal of the last phase of database design, physical design, is to implement the database. At this phase
one must know which database management system (DBMS) is used. For example, different DBMS's
have different names for datatypes and have different datatypes. The SQL clauses to create the database
are written. The idexes, the integrity constraints (rules) and the users' access rights are defined. Finally
the data to test the database is added in. In parallel with these activities, application programs are
designed. The implementation of the programs can start when the database is created and data has been
added in.
14
ENTITY RELATIONSHIP DIAGRAM (ERD)
Represents data entities associated with a system or business environment, the relationship among those
entities, and the specific attributes of both the entities and their relationships
Symbols used on ERDs:
ERD components
a) Entities:
Represented by a rectangle on the ERD
Represent data which could be people, places, objects, event, concepts, or whatever else an
organization wishes to maintain data about.
It can be distinguished from all of the other entities in the business environment by some set of
identifying characteristics or attributes.
It represents a class of things that can occur more than once within the business environment.
Entity type
A collection of entities that all share one or more common properties or attributes.
Entity instance
Represents a single, unique occurrence of a member of an entity type.
b) Attributes
Represented by an oval or ellipse on the ERD
A characteristic of an entity or a relationship
Example: The entity STUDENT could be described by attributes such as NAME, ADDRESS, ID
NUMBER, MAJOR, etc.
c) Key Attributes
An unique identifier of an entity
Can be a single attribute, or group of attributes
Example: The entity PRODUCT might be uniquely identified by a key PRODUCT ID
d) Concatenated/Composite/Compound Key
15
a. A group of attributes that uniquely identifies an instance of an entity
e) Candidate Key
a. A candidate to become the primary identifier
b. Example: The entity STUDENT could be uniquely identified by SSN, STUDENT ID, or E-
MAIL ADDRESS
f) Multivalued Attributes:
Multiple values for a single entity instance
Example: the attribute TRAINING of the entity EMPLOYEE can have more than one value at any given
time
16
1. We may not add a record to the Employees table unless the Managed by attribute points to a valid
record in the Managers table.
2. If the primary key for a record in the Managers table changes, all corresponding records in the
Employees table must be modified using a cascading update.
3. If a record in the Managers table is deleted, all corresponding records in the Employees table must
be deleted using a cascading delete.
4. Domain Integrity
The domain integrity states that every element from a relation should respect the type and restrictions of
its corresponding attribute. A type can have a variable length which needs to be respected. Restrictions
could be the range of values that the element can have, the default value if none is provided, and if the
element can be NULL.
RELATIONSHIPS
A relationship is an association between one or more entities
Relationship between STUDENT and COURSE entities
A STUDENT may be enrolled in zero, one, or more COURSES, and a COURSE may be
taken by zero, one, or more STUDENTS
Relationship Set: Collection of similar relationships.
Example of an ERD:
since
name dname
ssn lot did budget
The above ERD shows that an Employee (who is identified by social security number-ssn,
name and lot) works in a department; a department is identified by department id,
department name and budget.
The figures below also show how you can draw an ERD (especially on indicating
relationships), though attributes are not shown.
17
CONSTRAINT ON RELATIONSHIP TYPES
Two main Types of relationship constraints
a) Cardinality ration
b) Participation
a) Cardinality Ratios
Cardinality ratio specifies the maximum number of relationship instances that an entity can participate
i. 1 to 1 Relationship (1:1)
ii. 1 to many relationship(1:N)
iii. Many to Many relationship (N:M)
i. 1 to 1 Relationship (1:1)
A one-to-one relationship is between two tables where the primary key in one table and the
foreign key in another table are the same. For each record in the first table, there is a single
matching record in the second table.
ii. 1 to many relationship(1:N)
A one-to-many relationship occurs between two tables where the primary key in one table can
be duplicated many times in another table
iii. Many to Many relationship (N:M)
For particular records in one table there are many several matching records in the other table.
18
1-to-1 1-to Many Many-to-1 Many-to-Many
Note:
A good database design is, therefore, one that:
Divides your information into subject-based tables to reduce redundant data.
Provides Access with the information it requires to join the information in the tables together
as needed.
Helps support and ensure the accuracy and integrity of your information.
Accommodates your data processing and reporting needs.
SOME REVISION
Why would you choose a database system instead of simply storing data in operating system files? When
would it make sense not to use a database system?
Answer A database is an integrated collection of data, usually so large that it has to be stored on
secondary storage devices such as disks or tapes. This data can be maintained as a collection of operating
system files, or stored in a DBMS (database management system). The advantages of using a DBMS are:
Data independence and efficient access. Database application programs are independent of the details
of data representation and storage. The conceptual and external schemas provide independence from
physical storage decisions and logical design decisions respectively. In addition, a DBMS provides
efficient storage and retrieval mechanisms, including support for very large files, index structures and
query optimization.
Reduced application development time. Since the DBMS provides several important functions
required by applications, such as concurrency control and crash recovery, high level query facilities,
19
etc., only application-specific code needs to be written. Even this is facilitated by suites of application
development tools available from vendors for many database management systems.
Data integrity and security. The view mechanism and the authorization facilities of a DBMS provide
a powerful access control mechanism. Further, updates to the data that violate the semantics of the
data can be detected and rejected by the DBMS if users specify the appropriate integrity constraints.
Data administration. By providing a common umbrella for a large collection of data that is shared by
several users, a DBMS facilitates maintenance and data administration tasks. A good DBA can
effectively shield end-users from the chores of fine-tuning the data representation, periodic back-ups
etc.
Concurrent access and crash recovery. A DBMS supports the notion of a transaction, which is
conceptually a single user’s sequential program. Users can write transactions as if their programs
were running in isolation against the database.
The DBMS executes the actions of transactions in an interleaved fashion to obtain good performance, but
schedules them in such a way as to ensure that conflicting operations are not permitted to proceed
concurrently. Further, the DBMS maintains
a continuous log of the changes to the data, and if there is a system crash, it can restore the database to a
transaction-consistent state. That is, the actions of incomplete transactions are undone, so that the
database state reflects only the actions of completed transactions. Thus, if each complete transaction,
executing alone, maintains the consistency criteria, then the database state after recovery from a crash is
consistent.
MICROSOFT ACCESS
MICROSOFT ACCESS DATABASE OBJECTS
Tables- Allows the user to organize data into rows and columns.
Queries- Used to analyse or request for specific records from a database.
Forms- A form is a visual display that resembles an ordinary form used to enter or view records from
a table.
Reports- Used to generate reports or summaries from an underlying table or query.
Macros- Used to automate some operations such as displaying a startup form when you start Access.
Modules- This is a Visual Basic Programming environment that consists of a collection of
declarations and procedures used to automate other database objects.
Pages – Data access pages are used to create web-based databases.
CREATE A NEW DATABASE
Create a Table
20
You can create a new database from scratch or you can create a database from the database wizard.
New Database
To create a new database from scratch:
Click the Microsoft Office Button
Click New
Click the New Blank Database icon
Database Templates
To create a new database from the database templates:
Click the Microsoft Office Button
Click New
Choose the type of database you wish to create
Type in the name for the database
Click Create
21
Table Views
There are two ways to view a table in Access to add data to the table: Design View and Datasheet View.
In Design View you can view all the fields with the data types and descriptions. The records of
information that has been added to the database is not viewable.
To go to Design View:
Click the down arrow on the View button
Click Design View
In Datasheet View you can display the records in a table, where one row is one record. The column
headers are the fields you have defined for the database.
22
To go to Datasheet View:
Click the down arrow on the View button
Click Datash/eet View
Adding New Fields
There are many ways to enter new fields into a database. New fields can be added in the Datasheet View
or in the Design View.
There are two ways to add a new field in Datasheet View: Add A New Field or the New Field Button.
To add a New Field within the Datasheet:
Click the Add New Field column
To add a new field by using the New Field Button
Click the Datasheet tab on the Ribbon
Click the New Field Button
Choose the type of field you wish to add from the Field Templates window
23
Data Types
There are many types a data that a field can be predefined to hold. When you create a new field in a
database you should closely match the data type to what will be entered into the field.
24
To edit the Data Type in Datasheet View:
Click the field you wish to define
Click the Datasheet tab on the Ribbon
Click the down arrow next to Data Type
Choose the type of data that will be entered into the field
25
Property Usage
Field Size Allows the user to set the number of characters in a field instead of the default 50 for
text fileds, for numeric fields integer, bytes, single, double, or long integer is used.
Enter custom formatting characters to define a display format. You can format number
Format to scientific , currency, % etc.
For number or currency fields you can spcify the number of decimal places.
Caption Specifies the name of your Text field. Property accepts up to 2,048 characters. If you
don't specify a caption, Access applies the default field name.
Default Specifies the value that automatically appears in a field when you create a new record.
Value For example, Date() automatically displays current date.
Validation Specifies requirements for data entered into a record, field, or control. When you enter
Rule data that violates the rule defined for the field, you can use the Validation Text property
26
to specify the resulting error message. Maximum length: 2,048 characters.
The following table contains expression examples for the ValidationRule and
ValidationText properties.
>=#01/01/2007# AND
Date must occur in 2007
<#01/01/2008#
In addition to those rules, the following table shows the common arithmetic operators
and provides examples of how you can use them.
Validation Specifies the text in the error message that appears when users violate a validation rule.
Text Maximum length: 255 characters.
Required When set to Yes, you must enter a value in the field, or in any controls bound to the
field, and the value cannot be Null.
Allow Zero When set to Yes, you can enter zero-length strings in a field. A zero-length string
Length contains no characters, and you use them to indicate that you know no value exists for a
field. You enter a zero-length string by typing two double quotation marks with no
space between them ("").
Indexed You can use indexes to speed up queries, sorting, and grouping operations run against
large amounts of data.
NOT Tests for converse values. Use NOT > 10 (the same as <=10).
27
before any comparison operator
except IS NOT NULL.
BETWEEN Tests for a range of values. You BETWEEN 100 AND 1000
must use two comparison values — (the same as >=100 AND
low and high — and you must <=1000)
separate those values with the AND
separator.
AND Specifies that all the data that you >= #01/01/2007# AND
enter must be true or fall within <=#03/06/2008#
limits that you specify.
28
< Less than.
= Equal to.
Delete a Table
To delete a table:
Open the desired database by clicking the Microsoft Office Button and clicking Open
Right click on a table and choose Delete
Rename a Table
To rename a table:
Open the desired database by clicking the Microsoft Office Button and clicking Open
Right click on a table and choose Rename
Type in the new name
Add a Description to a Table
To add a description to a table
Open the desired database by clicking the Microsoft Office Button and clicking Open
Right click on a table and choose Table Properties
Click the Description text box
Type in the description
29
Primary Key
The primary key is a unique identifier for a record. The primary key cannot be the same for two records.
This field can never be blank.
Composite Key
A composite key is a primary key that is comprised of two or more fields. It can also be called a
compound or concatenated key.
Foreign Key
A foreign key is a field or combination of fields that are related to the primary key of another table.
Table Relationships
Table relationships are the associations of data between tables. By defining table relationships, you can
pull records from related tables based on matching fields.
30
1. One-to-One Relationship
A one-to-one relationship is between two tables where the primary key in one table and the foreign key in
another table are the same. For each record in the first table, there is a single matching record in the
second table.
2. One-to-Many Relationship
A one-to-many relationship occurs between two tables where the primary key in one table can be
duplicated many times in another table
31
3. Many-to-many relationship
For particular records in one table there are many several matching records in the other table.
Creating Table Relationships
To create relationships between tables:
Click the Database Tools tab on the Ribbon
Click the Relationships button
32
Select the desired tables
Click Add
Click Close
33
customers, rather than storing it repeatedly (and potentially inconsistently) in a table that contains
order data.
Efficiency Recording data in only one place means you use less disk space. Moreover, smaller tables
tend to provide data more quickly than larger tables. Finally, if you don't use separate tables for
separate subjects, you will introduce null values (the absence of data) and redundancy into your
tables, both of which can waste space and impede performance.
Comprehensibility The design of a database is easier to understand if the subjects are properly
separated into tables.
Totals
The totals button provides you the opportunity to add a totals row to your database. The total can be the
sum, average, a count, minimum, maximum, standard deviation, or the variance. To set up a totals row:
Click the Totals button on the Home tab
Click the down arrow of the cell where you want the totals
Click the appropriate choice
Sort Records
You can sort records in a datasheet by a single column or by two adjacent columns. To sort records by a
single column:
34
Select the field you wish to sort
Click the Sort Ascending or Sort Descending button
Filter
You can filter records to include only records that you want to display. To filter by a column:
Open the database in Datasheet View
Click the down arrow in the field label
Choose the appropriate filter criteria
Click OK
To remove a filter:
Click the filter button on the field label
Click Clear Filter
Click OK
35
QUERYING A DATABASE
A query allows you to select and filter data from multiple tables. Queries can be saved and utilized as
often as you need them.
Types of queries in MS Access
Select query: Used for searching and analyzing data in one or more table.
Action query: Used for modifying data in one or more tables.
Four kinds of action queries are:
1. Append Query – takes the set results of a query and "appends" (or adds) them to an existing
table.
2. Delete Query – deletes all records in an underlying table from the set results of a query.
3. Make Table Query – as the name suggests, it creates a table based on the set results of a
query.
4. Update Query – allows for one or more field in your table to be updated.
Parameter Query
In Microsoft Access, a parameter query works with other types of queries to get whatever results you are
after. This is because, when using this type of query, you are able to pass a parameter to a different query,
such as an action or a select query. It can either be a value or a condition and will essentially tell the other
query specifically what you want it to do.
36
It is often chosen because it allows for a dialog box where the end user can enter whatever parameter
value they wish each time the query is run. The parameter query is just a modified select query.
Aggregate Query
A special type of query is known as an aggregate query. It can work on other queries (such as selection,
action or parameter) just like the parameter query does, but instead of passing a parameter to another
query it totals up the items by selected groups.
It essentially creates a summation of any selected attribute in your table. This can be further generated
into statistical amounts such as averages and standard deviation, just to name a couple.
The SQL aggregate functions available to Microsoft Access are:
Sum
Avg
Min
Max
First
Query Wizard
The Query Wizard takes you through the steps to set up a query. To run a query using the query wizard:
Click the Create tab
Click the Query Wizard button
37
To select fields from different tables, click the Tables/Queries down arrow
Click Next
38
Query Design Feature
You can also design a query with the Query Design Button. To design a query using the Query Design
Button:
Click the Query Design Button on the Create tab
Double click the name of the field you would like to query
Repeat this process for as many fields as you would like in the query
39
Click Run
Query Criteria
Query criteria are search conditions used in a query to retrieve specific data. You can set query criteria to
be a specific number or data set, or you can set the criteria to be a range of data.
Criteria for Text, Memo, and Hyperlink fields
40
Exactly match a value, such as "China" Returns records where the CountryRegion
China field is set to China.
Do not match a value, such as Not "Mexico" Returns records where the CountryRegion
Mexico field is set to a country/region other than
Mexico.
Begin with the specified Like U* Returns records for all countries/regions
string, such as U whose names start with "U", such as UK,
USA, and so on.
Do not begin with the Not Like U* Returns records for all countries/regions
specified string, such as U whose names start with a character other
than "U".
Contain the specified string, Like "*Korea*" Returns records for all countries/regions
such as Korea that contain the string "Korea".
Do not contain the specified Not Like "*Korea*" Returns records for all countries/regions
string, such as Korea that do not contain the string "Korea".
End with the specified string, Like "*ina" Returns records for all countries/regions
such as "ina" whose names end in "ina", such as China
and Argentina.
Contain null (or missing) Is Null Returns records where there is no value in
values the field.
Criteria for Number, Currency, and AutoNumber fields
The following examples are for the UnitPrice field in a query that is based on a table that stores products
information. The criterion is specified in the Criteria row of the field in the query design grid.
41
To include records
that... Use this criterion Query Result
Exactly match a value, 100 Returns records where the unit price of the product is $100.
such as 100
Do not match a value, Not 1000 Returns records where the unit price of the product is not
such as 1000 $1000.
Contain a value < 100 Returns records where the unit price is less than $100 (<100).
smaller than a value, <= 100 The second expression (<=100) displays records where the
such as 100 unit price is less than or equal to $100.
Contain a value larger >99.99 Returns records where the unit price is greater than $99.99
than a value, such as >=99.99 (>99.99). The second expression displays records where the
99.99 unit price is greater than or equal to $99.99.
Contain one of the two 20 or 25 Returns records where the unit price is either $20 or $25.
values, such as 20 or
25
Contain a value that >49.99 and Returns records where the unit price is between (but not
falls with a range of <99.99 including) $49.99 and $99.99.
values -or-
Between 50 and
100
Contain a value that <50 or >100 Returns records where the unit price is not between $50 and
42
falls outside a range $100.
Contain null null (or Is Null Returns records where no value is entered in the UnitPrice
missing) values field.
Contain non-null Is Not Null Returns records where the value is not missing in the
values UnitPrice field.
Criteria for Date/Time fields
The following examples are for the OrderDate field in a query based on a table that stores Orders
information. The criterion is specified in the Criteria row of the field in the query design grid.
Exactly match a value, #2/2/2006# Returns records of transactions that took place on
such as 2/2/2006 Feb 2, 2006. Remember to surround date values with
the # character so that Access can distinguish
between date values and text strings.
Do not match a value, Not #2/2/2006# Returns records of transactions that took place on a
such as 2/2/2006 day other than Feb 3, 2006.
Contain values that fall < #2/2/2006# Returns records of transactions that took place
before a certain date, such before Feb 2, 2006.
as 2/2/2006 To view transactions that took place on or before
this date, use the <= operator instead of the <
operator.
43
Contain values that fall > #2/2/2006# Returns records of transactions that took place after
after a certain date, such Feb 2, 2006.
as 2/2/2006 To view transactions that took place on or after this
date, use the >= operator instead of the > operator.
Contain values that fall >#2/2/2006# and Returns records where the transactions took place
within a date range <#2/4/2006# between Feb 2, 2006 and Feb 4, 2006.
You can also use the Between operator to filter for a
range of values. For example, Between #2/2/2006#
and #2/4/2006# is the same as >#2/2/2006# and
<#2/4/2006# .
Contain values that fall <#2/2/2006# or Returns records where the transactions took place
outside a range >#2/4/2006# before Feb 2, 2006 or after Feb 4, 2006.
Wild cards
They are special symbols used instead of the actual characters.
Character Description Example
* Matches any number of characters Wh* finds what, when,why, walloga
etc.
? Matches any single character within B?ll Finds ball, bell, bull etc
brackets
[] Matches any single character within bracket T[eo]ll Finds Tell, Toll, but not Tall
! Matches any character not in the brackets B[!ae] finds bill, but not ball or bell
# Matches any single numeric character 1#3 Finds 103, 113, 123, 143
44
Calculated Fields
A calculated field is a field that gets its information from the calculations performed on other fields. You
can build calculated fields in the Query screen by using the addition (+), subtraction (-), multiplication
(*) and division (/) operators.
Expressions
Expressions a combination of functions, field names, numbers, text, and the operators listed above.
To build an expression to create a calculated field:
Open an existing query or start a new query
Click on the View Button
Click on Design View
In the Query Pane, right-click on the field where you would like to create the calculation
Click Build
Choose the tables that you wish to build the calculation from
Double-click the field that you want to include in the calculation
Click the operator that you wish to include in the calculation
Click the second field you wish to include in the calculation
Click OK
45
Click Run
DESIGNING FORMS
Forms allow you to control the look and feel of the screen for the input of data and the reports generated.
Form Views
There are three ways to view forms in Access:
Allows you to design a form that includes a header, a footer, and
Design View details in the form. You can also add images and control which
fields appear on the form.
Form View This is a dynamic page which allows the user to enter and edit data
or navigate through data in a field.
Layout View This view allows you to design the form and manipulate data.
Create a Form
You can create a form from a table or a query. To create a form:
Click the Create tab
Click the Form Design button
46
To change the colors and fonts, click the Property Sheet button on the Arrange tab
Form Wizard
You can create forms with the help of the Form Wizard. To use the form wizard:
On the create tab, click the More Forms down arrow
47
Click Form Wizard
48
Choose a style
Click Next
Note:
There are two types of form controls:
Bound control- This is a control whose source of data is a field from an underlying table or
query.
Unbounded control- This is a control that is not tied to any data source.
49
Create a form that contains a subform by using the Form Wizard
This procedure creates a new form and subform combination by using the Form Wizard.
1. On the Create tab, in the Forms group, click More Forms, and then click
2.
3.
4. Form Wizard.
50
8. When you click Next, assuming that you set up the relationships correctly before starting the wizard,
the wizard asks How do you want to view your data? — that is, by which table or query. For this
example, to create the Categories form, click by Categories. The wizard displays a small diagram of
the form. The box in the lower portion of the form represents the subform.
9. At the bottom of the wizard page, select the Form with subform(s) option, and then click Next.
10. On the What layout would you like for your subform? page of the wizard, click Tabular or
Datasheet depending on which layout you want for your subform. Both layout styles arrange the
subform data in rows and columns, but a tabular layout is more customizable. You can add color,
graphics, and other formatting elements to a tabular subform, whereas a datasheet is more compact,
like the datasheet view of a table. When you have made your selection, click Next.
11. On the What style would you like? page of the wizard, select a formatting style for the form. If you
chose Tabular on the previous page, the formatting style you choose will also be applied to the
subform. When you have made your selection, click Next.
12. On the last page of the wizard, type the titles you want for the forms. Access names the forms based
on the titles you type, and labels the subform based on the title you type for the subform.
Also on this page, specify whether you want to open the form in Form view so that you can view or
enter information, or whether you want to open the form in Design view so that you can modify its
design. When you have made your selection, click Finish.
Access creates two forms — one for the main form that contains the subform control, and one for
the subform itself.
GENERATING REPORTS
Reports are a means to view and analyze large amounts of data. You can use the Report Wizard or
create a custom report that meets your specific needs.
Report Views
Reports can be displayed in four views:
This view provides you with the structure of your report.
Design View You can add, modify or delete components of the report but
you cannot manipulate the data in the tables associated with
the report.
Report View This view allows you to view the data from the table but not
51
to change any layout of the report.
Layout View This view allows you to see data from the table and add,
modify, and delete components of the report.
Print Preview This view allows you to see what your report will look like
when it is printed.
To change report views:
Click the View button on the Home tab
Report Wizard
To create a report using the report wizard:
On the Create tab, click the Report Wizard button
52
Create a title for the form
Choose whether you want to open the form to view it or modify the form’s design
Click Finish
Click the section on the report where you would like to locate the textbox
Click the Property Sheet Pane
53
Click the Data tab
Click the three dots next to Control Source
Parts of a report
Report header: displays the title of the report.
Page header: Contains headings for data items displayed in every column.
Details: displays data items or records from an underlying table or query.
Page footer: Used to display footer on every page of the report, e.g date and page number.
Report footer- displays summary from the report, e.g grand totals.
54
SAMPLE EXAM PAPER I
INSTRUCTIONS:
Attempt Question 1 (compulsory - 20 marks) and any other TWO Questions (20 marks each).
55
d. Give any three database applications. (3marks)
QUESTION FOUR (20 marks):
a. Describe the procedure of creating a blank database (4 marks)
b. Explain how sorting of records is done in databases (5 marks)
c. Explain three advantages and three disadvantages of using a database (6 marks)
d. Differentiate between Forms and Reports (5 marks).
QUESTION FIVE (20 marks):
a. Explain what a primary key is and give an example (2 marks)
b. What are the qualities of good information? (2 marks)
c. Explain by giving examples, the following field properties (4 marks)
a) Input mask.
b) Field size.
d. Outline the four benefits for designing a table from scratch rather than using a table wizard (2 marks)
e. Explain the factors a person wishing to acquire a DBMS should take into account before purchasing
the DBMS he needs to run his business. (8 marks)
f. Explain two ways to filter records in Ms Access (4 marks)
SAMPLE EXAM PAPER II
INSTRUCTIONS:
Attempt Question 1 (compulsory - 20 marks) and any other TWO Questions (20 marks each).
56
g. Microsoft Access databases consist of various elements. Name them.
(5 marks)
Hardware
Software
Data
Procedures
People
h. Differentiate between Record and Field (4 marks)
Record-data that is organized in rows in a table
Field-an element of a table that contains a specific item of information .It is represented by a
column or cell in a datasheet.
i. Different the following data types as used in Microsoft Access. (2 marks)
i) Number
ii) AutoNumber
57
b. Outline five factors to consider when developing a database (5 marks)
Purpose of the database
Entities in the user environment
Their attributes
Relationship among entities
End- users
c. Explain three benefits and three limitations of using a database (6 marks)
Benefits:
-Control of data redundancy
-Improved Security
-Improved backup and recovery services
-Improved consistency
Limitations:
-Complexity
-Cost
-Memory Size
-Require specialized persons
High impact of failure
d. Explain any five functions of a Database Management System (5 marks)
QUESTION THREE (20 marks):
a. Discuss various advantages of using queries in database (6 marks)
With queries you can:
-Choose fields for inclusion and viewing.
-Sort records
-Ask and answer questions about your data, by specifying criteria
-Perform calculations about the data
-Use query as source of data for Forms, Reports and other queries
-Make changes to data (modify).
b. Name and explain four types of queries used in Ms access (8 marks)
c. Why is setting criteria in Ms access queries important (3marks)
d. Give any three database applications. (3marks)
-Business and trade
58
-Tourism industry
-Insurance
-Educational institutions
-Financial institutions
QUESTION FOUR (20 marks):
a. Describe the procedure of creating a blank database (4 marks)
Open Microsoft Access. From the File menu, click New, then Blank Database. Click OK.
A window appears, asking you to name and save your database, then type a name of
database. Click Create. Your new database window appears.
b. Explain how sorting of records is done in databases (5 marks)
Identify the fields on which you want to sort. To sort on two or more fields, identify the fields that
will act as the innermost and outermost sort fields.
Right-click anywhere in the column or control corresponding to the innermost field, and click one
of the sort commands. The commands vary with the type of data that is in the selected field.
d. Explain three advantages and three disadvantages of using a database (6 marks)
Advantages
-Control of data redundancy
-Improved Security
-Improved backup and recovery services
-Improved consistency
Disadvantages:
-Complexity
-Cost
-Memory Size
-Require specialized persons
-High impact of failure
e. Differentiate between Forms and Reports (5 marks)
i. In forms, fields are organized together with their labels on the detail section while in
reports, labels are placed on the page header.
Forms do not provide the option of sorting and grouping while it is in reports.
ii. Forms can be viewed in four different views (data sheet, single form, continuous form and
print preview.), while in a report can only be viewed in one view (print preview)
59
iii. A form can be used as a switch board for other objects due to its various views. Whereas
in a report, you can’t execute any control apart from viewing them.
QUESTION FIVE (20 marks):
g. Explain what a primary key is and give an example (2 marks)
A field that uniquely identifies each individual records in the table.
h. What are the qualities of good information? (2 marks)
Relevancy
Accuracy
Timeliness
i. Explain by giving examples, the following field properties (4 marks)
c) Input mask- displays the layout of the field.
d) Field size- sets the size and type of numbers to enter in the field.
j. Outline the four benefits for designing a table from scratch rather than using a table wizard (2 marks)
It gives one control of the field naming and data types selection
It provides a means of defining the fields by entering fields’ description
It enables one to specify the fields’ properties hence ease the data entry and management
It doesn’t require a lot of memory to run hence it is quick even in a slower computer.
d. Explain the factors a person wishing to acquire a DBMS should take into account before purchasing
the DBMS he needs to run his business. (8 marks)
-Cost -Security features -Recovery features -User interface
-Memory requirements
e. Explain two ways to filter records in Ms Access (4 marks)
Filter by selection
Filter by Form
60