RDBMS & MS Access
History
• IBM Sequel language developed as part of System R project
at the IBM San Jose Research Laboratory
• Renamed Structured Query Language (SQL)
• ANSI and ISO standard SQL:
– SQL-86
– SQL-89
– SQL-92
– SQL:1999 (language name became Y2K compliant!)
– SQL:2003
• Commercial systems offer most, if not all, SQL-92 features,
plus varying feature sets from later standards and special
proprietary features.
– Not all examples here may work on your particular system.
Data Definition Language
Allows the specification of:
• The schema for each relation, including attribute
types.
• Integrity constraints
• Authorization information for each relation.
• Non-standard SQL extensions also allow specification
of
– The set of indices to be maintained for each relations.
– The physical storage structure of each relation on disk.
RDBMS
• RDBMS stands for Relational Database
Management System.
• RDBMS is the basis for SQL, and for all
modern database systems such as MS
SQL Server, IBM DB2, Oracle, MySQL, and
Microsoft Access.
• The data in RDBMS is stored in database
objects called tables. A table is a
collection of related data entries and it
consists of columns and rows.
RDBMS
• Every table is broken up into smaller entities
called fields. The fields in the Customers table
consist of CustomerID, CustomerName,
ContactName, Address, City, PostalCode and
Country. A field is a column in a table that is
designed to maintain specific information about
every record in the table.
• A record, also called a row, is each individual
entry that exists in a table. For example, there
are 91 records in the above Customers table. A
record is a horizontal entity in a table.
• A column is a vertical entity in a table that
contains all information associated with a
specific field in a table.
Database Tables
• A database most often contains one
or more tables. Each table is
identified by a name (e.g.
"Customers" or "Orders"). Tables
contain records (rows) with data.
Data Manipulation Language (DML)
• Language for accessing and manipulating the
data organized by the appropriate data model
– DML also known as query language
• Two classes of languages
– Procedural – user specifies what data is required and
how to get those data
– Declarative (nonprocedural) – user specifies what
data is required without specifying how to get those
data
• SQL is the most widely used query language
Data Definition Language (DDL)
• Specification notation for defining the database schema
Example: create table account (
account-number char(10),
balance integer)
• DDL compiler generates a set of tables stored in a data
dictionary
• Data dictionary contains metadata (i.e., data about data)
– Database schema
– Data storage and definition language
• Specifies the storage structure and access methods used
– Integrity constraints
• Domain constraints
• Referential integrity (references constraint in SQL)
• Assertions
– Authorization
– Read Authorization
– Insert Authorization
– Update Authorization
– Delete Authorization
MS Access
MS Access
• Microsoft Access is a Database Management
System (DBMS) from Microsoft that combines
the relational Microsoft Jet Database Engine
with a graphical user interface and
softwaredevelopment tools. It is a part of the
Microsoft Office suite of applications, included
in the professional and higher editions.
MS Access
• Microsoft Access is just one part of Microsoft’s overall
data management product strategy.
• It stores data in its own format based on the Access Jet
Database Engine.
• Like relational databases, Microsoft Access also allows
you to link related information easily. For example,
customer and order data. However, Access 2013 also
complements other database products because it has
several powerful connectivity features.
• It can also import or link directly to data stored in
other applications and databases.
MS Access
• As its name implies, Access can work directly with data from other
sources, including many popular PC database programs, with many
SQL (Structured Query Language) databases on the desktop, on
servers, on minicomputers, or on mainframes, and with data stored
on Internet or intranet web servers.
• Access can also understand and use a wide variety of other data
formats, including many other database file structures.
• You can export data to and import data from word processing files,
spreadsheets, or database files directly.
• Access can work with most popular databases that support the
Open Database Connectivity (ODBC) standard, including SQL Server,
Oracle, and DB2.
• Software developers can use Microsoft Access to develop
application software.
MS Access
• Microsoft Access stores information which is called a
database. To use MS Access, you will need to follow these
four steps −
• Database Creation − Create your Microsoft Access
database and specify what kind of data you will be storing.
• Data Input − After your database is created, the data of
every business day can be entered into the Access
database.
• Query − This is a fancy term to basically describe the
process of retrieving information from the database.
• Report (optional) − Information from the database is
organized in a nice presentation that can be printed in an
Access Report.
Architecture
• Access calls anything that can have a name an object.
Within an Access desktop database, the main objects
are tables, queries, forms, reports, macros, data
macros, and modules.
• If you have worked with other database systems on
desktop computers, you might have seen the term
database used to refer to only those files in which you
store data.
• But, in Access, a desktop database (.accdb) also
includes all the major objects related to the stored
data, including objects you define to automate the use
of your data.
• Microsoft Access has the look and feel of
other Microsoft Office products as far as its
layout and navigational aspects are
concerned, but MS Access is a database and,
more specifically, a relational database.
MS Access - RDBMS
• Before MS Access 2007, the file extension was *.mdb, but in
MS Access 2007 the extension has been changed to *.accdb
extension.
• Early versions of Access cannot read accdb extensions but MS
Access 2007 and later versions can read and change earlier
versions of Access.
• An Access desktop database (.accdb or .mdb) is a fully
functional RDBMS.
MS Access - RDBMS
• It provides all the data definition, data manipulation, and data
control features that you need to manage large volumes of
data.
• You can use an Access desktop database (.accdb or .mdb)
either as a standalone RDBMS on a single workstation or in a
shared client/server mode across a network.
• A desktop database can also act as the data source for data
displayed on webpages on your company intranet.
• When you build an application with an Access desktop
database, Access is the RDBMS.
MS Access - RDBMS
• It provides all the data definition, data manipulation, and data
control features that you need to manage large volumes of
data.
• You can use an Access desktop database (.accdb or .mdb)
either as a standalone RDBMS on a single workstation or in a
shared client/server mode across a network.
• A desktop database can also act as the data source for data
displayed on webpages on your company intranet.
• When you build an application with an Access desktop
database, Access is the RDBMS.
Data Definition
• Let us now understand what Data Definition is −
• In document or a spreadsheet, you generally have complete
freedom to define the contents of the document or each cell
in the spreadsheet.
• In a document, you can include paragraphs of text, a table, a
chart, or multiple columns of data displayed with multiple
fonts.
• In spreadsheet, you can have text data at the top to define a
column header for printing or display, and you might have
various numeric formats within the same column, depending
on the function of the row.
Data Definition
• An RDBMS allows you to define the kind of data you have and
how the data should be stored.
• You can also usually define rules that the RDBMS can use to
ensure the integrity of your data.
• For example, a validation rule might ensure that the user
can’t accidentally store alphabetic characters in a field that
should contain a number.
Data Manipulation
• Working with data in RDBMS is very different from working
with data in a word processing or spreadsheet program.
• In a word processing document, you can include tabular data
and perform a limited set of functions on the data in the
document.
• You can also search for text strings in the original document
and, with ActiveX controls, include tables, charts, or pictures
from other applications.
• In a spreadsheet, some cells contain functions that determine
the result you want, and in other cells, you enter the data
that provides the source information for the functions.
Data Manipulation
• An RDBMS provides you many ways to work with your data.
For example,
• You can search a single table for information or request a
complex search across several related tables.
• You can update a single field or many records with a single
command.
• You can write programs that use RDBMS commands to fetch
data that you want to display and allow the user to update
the data.
Data Manipulation
• An RDBMS provides you many ways to work with your data.
For example,
• You can search a single table for information or request a
complex search across several related tables.
• You can update a single field or many records with a single
command.
• You can write programs that use RDBMS commands to fetch
data that you want to display and allow the user to update
the data.
Data Manipulation
• Access uses the powerful SQL database language to process
data in your tables. Using SQL, you can define the set of
information that you need to solve a particular problem,
including data from perhaps many tables.
Data Control
• Spreadsheets and word processing documents are great for
solving single-user problems, but they are difficult to use when
more than one person needs to share the data.
– When you need to share your information with others, RDBMS gives you the
flexibility to allow multiple users to read or update your data.
– An RDBMS that is designed to allow data sharing also provides features to
ensure that no two people can change the same data at the same time.
– The best systems also allow you to group changes (which is also known as
transaction) so that either all the changes or none of the changes appear in
your data.
– You might also want to be sure that no one else can view any part of the
order until you have entered all of it.
– Because you can share your Access data with other users, you might need to
set some restrictions on what various users are allowed to see or update.
MS Access - Objects
• MS Access uses “objects" to help the user list and organize
information, as well as prepare specially designed reports. When
you create a database, Access offers you Tables, Queries, Forms,
Reports, Macros, and Modules. Databases in Access are composed
of many objects but the following are the major objects −
• Tables
• Queries
• Forms
• Reports
Together, these objects allow you to enter, store, analyze, and
compile your data. Here is a summary of the major objects in an
Access database;
MS Access - Objects
• Table
– Table is an object that is used to define and store data. When you
create a new table, Access asks you to define fields which is also
known as column headings.
– Each field must have a unique name, and data type.
– Tables contain fields or columns that store different kinds of
data, such as a name or an address, and records or rows that
collect all the information about a particular instance of the
subject, such as all the information about a customer or
employee etc.
– You can define a primary key, one or more fields that have a
unique value for each record, and one or more indexes on each
table to help retrieve your data more quickly.
MS Access - Objects
• Query
– An object that provides a custom view of data from one or more
tables. Queries are a way of searching for and compiling data from
one or more tables.
– Running a query is like asking a detailed question of your database.
– When you build a query in Access, you are defining specific search
conditions to find exactly the data you want.
– In Access, you can use the graphical query by example facility or you
can write Structured Query Language (SQL) statements to create your
queries.
– You can define queries to Select, Update, Insert, or Delete data.
– You can also define queries that create new tables from data in one
or more existing tables.
MS Access - Objects
• Form
– Form is an object in a desktop database designed primarily
for data input or display or for control of application
execution. You use forms to customize the presentation of
data that your application extracts from queries or tables.
– Forms are used for entering, modifying, and viewing records.
– The reason forms are used so often is that they are an easy
way to guide people toward entering data correctly.
– When you enter information into a form in Access, the data
goes exactly where the database designer wants it to go in
one or more related tables.
MS Access - Objects
• Report
– Report is an object in desktop databases designed for formatting,
calculating, printing, and summarizing selected data.
– You can view a report on your screen before you print it.
– If forms are for input purposes, then reports are for output.
– Anything you plan to print deserves a report, whether it is a list of
names and addresses, a financial summary for a period, or a set of
mailing labels.
– Reports are useful because they allow you to present components of
your database in an easy-to-read format.
– You can even customize a report's appearance to make it visually
appealing.
– Access offers you the ability to create a report from any table or query
MS Access - Objects
• Other MS Access Objects
• Let us now take a look at other MS Access objects.
• Macro
• This object is a structured definition of one or more actions
that you want Access to perform in response to a defined
event. An Access Macro is a script for doing some job. For
example, to create a button which opens a report, you could
use a macro which will fire OpenReport action.
• You can include simple conditions in macros to specify when
one or more actions in the macro should be performed or
skipped.
MS Access - Objects
• You can use macros to open and execute queries, to open
tables, or to print or view reports.
• You can also run other macros or Visual Basic procedures
from within a macro.
• Data macros can be attached directly to table events such as
inserting new records, editing existing records, or deleting
records.
• Data macros in web apps can also be stand-alone objects that
can be called from other data macros or macro objects.
MS Access - Objects
• Module
• Module is an object in desktop databases containing custom procedures
that you code using Visual Basic. Modules provide a more discrete flow of
actions and allow you to trap errors.
• Everything that can be done in a macro can also be done in a module, but
you don't get the macro interface that prompts you what is needed for
each action.
• Modules are far more powerful, and are essential if you plan to write code
for a multi-user environment, because macros cannot include error
handling.
• Modules can be standalone objects containing functions that can be called
from anywhere in your application, or they can be directly associated with
a form or a report to respond to events on the associated form or report.
MS Access - Create Database
• To create a database from a template, we first need to open
MS Access and you will see the following screen in which
different Access database templates are displayed.
MS Access - Create Database
• To view the all the possible databases, you can scroll down or
you can also use the search box.
• Let us enter project in the search box and press Enter. You
will see the database templates
MS Access - Create Database
• Select the first template. You will see more information
related to this template.
MS Access - Create Database
• After selecting a template related to your requirements, enter
a name in the File name field and you can also specify
another location for your file if you want.
MS Access - Create Database
• Now, press the Create option. Access will download that
database template and open a new blank database as shown
in the following screenshot.
MS Access - Create Database
• Now, click the Navigation pane on the left side and you will
see all the other objects that come with this database.
MS Access - Create Database
• Click the Projects Navigation and select the Object Type in the
menu.
MS Access - Create Database
• You will now see all the objects types — tables, queries, etc.
MS Access - Create Database
• Create Blank Database
• Sometimes database requirements can be so specific that
using and modifying the existing templates requires more
work than just creating a database from scratch. In such case,
we make use of blank database.
• Step 1 − Let us now start by opening MS Access.
MS Access - Create Database
• Step 3 − Access will create a new blank database and will
open up the table which is also completely blank.
MS Access - Data Types
• Every field in a table has properties and these properties
define the field's characteristics and behavior. The most
important property for a field is its data type. A field's data
type determines what kind of data it can store. MS Access
supports different types of data, each with a specific purpose.
• The data type determines the kind of the values that users
can store in any given field.
• Each field can store data consisting of only a single data type.
MS Access - Data Types
• Every field in a table has properties and these properties
define the field's characteristics and behavior. The most
important property for a field is its data type. A field's data
type determines what kind of data it can store. MS Access
supports different types of data, each with a specific purpose.
• The data type determines the kind of the values that users
can store in any given field.
• Each field can store data consisting of only a single data type.
• The data type determines the kind of the
values that users can store in any given field.
• Each field can store data consisting of only a
single data type.
• Here are some of the most common data
types you will find used in a typical Microsoft
Access database.
Type of Data Description Size
Text or combinations of text and
numbers, including numbers that do
Short Text Up to 255 characters.
not require calculating (e.g. phone
numbers).
Lengthy text or combinations of text
Long Text Up to 63, 999 characters.
and numbers.
Numeric data used in mathematical 1, 2, 4, or 8 bytes (16 bytes if set to
Number
calculations. Replication ID).
Date and time values for the years
Date/Time 8 bytes
100 through 9999.
Currency values and numeric data
used in mathematical calculations
Currency 8 bytes
involving data with one to four
decimal places.
A unique sequential (incremented by
1) number or random number
4 bytes (16 bytes if set to Replication
AutoNumber assigned by Microsoft Access
ID).
whenever a new record is added to a
table.
Yes and No values and fields that
Yes/No contain only one of two values 1 bit.
(Yes/No, True/False, or On/Off).
• If you use previous versions of Access, you will notice
a difference for two of those data types.
• In Access 2013, we now have two data types — short
text and long text. In previous versions of Access
these data types were called text and memo.
• The text field is referred to as short text and your
memo field is now called long text.
• Here are some of the other more specialized data
types, you can choose from in Access.
Data Types Description Size
Files, such as digital photos. Multiple
files can be attached per record. This
Attachment Up to about 2 GB.
data type is not available in earlier
versions of Access.
OLE objects can store pictures,
OLE objects audio, video, or other BLOBs (Binary Up to about 2 GB.
Large Objects)
Text or combinations of text and Up to 8,192 (each part of a Hyperlink
Hyperlink numbers stored as text and used as data type can contain up to 2048
a hyperlink address. characters).
The Lookup Wizard entry in the Data
Type column in the Design view is
not actually a data type. When you
choose this entry, a wizard starts to
help you define either a simple or
complex lookup field.
Dependent on the data type of the
Lookup Wizard A simple lookup field uses the
lookup field.
contents of another table or a value
list to validate the contents of a
single value per row. A complex
lookup field allows you to store
multiple values of the same data
type in each row.
You can create an expression that You can create an expression that
uses data from one or more fields. uses data from one or more fields.
Calculated
You can designate different result You can designate different result
data types from the expression. data types from the expression.
• These are all the different data types that you
can choose from when creating fields in a
Microsoft Access table.
MS Access - Create Tables
• When you create a database, you store your data in tables.
Because other database objects depend so heavily on tables,
you should always start your design of a database by creating
all of its tables and then creating any other object. Before you
create tables, carefully consider your requirements and
determine all the tables that you need.
• Let us try and create the first table that will store the basic
contact information concerning the employees as shown in
the following table −
Field Name Data Type
EmployeelD AutoNumber
FirstName Short Text
LastName Short Text
Address1 Short Text
Address2 Short Text
City Short Text
State Short Text
Zip Short Text
Phone Short Text
Phone Type Short Text
Let us now have short text as the data type for
all these fields and open a blank database in
Access.
This is where we left things off. We created the
database and then Access automatically opened
up this table-one-datasheet view for a table.
• Let us now go to the Field tab and you will see
that it is also automatically created. The ID
which is an AutoNumber field acts as our
unique identifier and is the primary key for
this table.
• The ID field has already been created and we
now want to rename it to suit our conditions.
This is an Employee table and this will be the
unique identifier for our employees.
Click on the Name & Caption option in the
Ribbon and you will see the following
dialog box.
• Change the name of this field to EmployeeID to
make it more specific to this table. Enter the
other optional information if you want and click
Ok.
• We now have our employee ID field with the
caption Employee ID. This is automatically set
to auto number so we don't really need to
change the data type.
• Let us now add some more fields by clicking
on click to add.
Choose Short Text as the field. When you choose short
text, Access will then highlight that field name
automatically and all you have to do is type the field
name.
Type FirstName as the field name. Similarly, add
all the required fields as shown in the following
screenshot.
Once all the fields are added, click the Save icon.
You will now see the Save As dialog box, where
you can enter a table name for the table.
• Enter the name of your table in the Table
Name field. Here the tbl prefix stands for
table. Let us click Ok and you will see your
table in the navigation pane.
Table Design View
• As we have already created one table using
Datasheet View. We will now create another
table using the Table Design View. We will be
creating the following fields in this table.
These tables will store some of the
information for various book projects.
Field Name Data Type
Project ID AutoNumber
ProjectName Short Text
ManagingEditor Short Text
Author Short Text
PStatus Short Text
Contracts Attachment
ProjectStart Date/Time
ProjectEnd Date/Time
Budget Currency
ProjectNotes Long Text
Let us now go to the Create tab.
In the tables group, click on Table and you can see this
looks completely different from the Datasheet View. In
this view, you can see the field name and data type
side by side.
We now need to make ProjectID a primary key
for this table, so let us select ProjectID and click
on Primary Key option in the ribbon.
You can now see a little key icon that will show up next to that
field. This shows that the field is part of the table’s primary key.
Let us save this table and give this table a name.
• Click Ok and you can now see what this table
looks like in the Datasheet View.
Let us click the datasheet view button on
the top left corner of the ribbon.
If you ever want to make changes to this table or any specific
field, you don't always have to go back to the Design View to
change it. You can also change it from the Datasheet View. Let
us update the PStatus field as shown in the following screenshot.
• Click Ok and you will see the changes.
MS Access - Adding Data
• An Access database is not a file in the same sense as a
Microsoft Office Word document or a Microsoft Office
PowerPoint are. Instead, an Access database is a collection of
objects like tables, forms, reports, queries etc. that must work
together for a database to function properly.
• We have now created two tables with all of the fields and
field properties necessary in our database. To view, change,
insert, or delete data in a table within Access, you can use the
table’s Datasheet View.
• A datasheet is a simple way to look at your data in
rows and columns without any special formatting.
• Whenever you create a new web table, Access
automatically creates two views that you can start
using immediately for data entry.
• A table open in Datasheet View resembles an Excel
worksheet, and you can type or paste data into one
or more fields.
• You do not need to explicitly save your data. Access commits
your changes to the table when you move the cursor to a new
field in the same row, or when you move the cursor to another
row.
• By default, the fields in an Access database are set to accept a
specific type of data, such as text or numbers. You must enter
the type of data that the field is set to accept. If you don't,
Access displays an error message −
• Let us add some data into your tables by opening the Access
database we have created.
Select the Views → Datasheet View option in the
ribbon and add some data as shown in the following
screenshot.
Similarly, add some data in the second table as
well as shown in the following screenshot.
• You can now see that inserting a new data and
updating the existing data is very simple in
Datasheet View as working in spreadsheet.
But if you want to delete any data you need to
select the entire row first as shown in the
following screenshot.
Now press the delete button. This will
display the confirmation message.
• Click Yes and you will see that the selected
record is deleted now.
MS Access - Query Data
• A query is a request for data results, and for
action on data. You can use a query to answer
a simple question, to perform calculations, to
combine data from different tables, or even to
add, change, or delete table data.
• As tables grow in size they can have hundreds of thousands of records,
which makes it impossible for the user to pick out specific records from
that table.
• With a query you can apply a filter to the table's data, so that you only get
the information that you want.
• Queries that you use to retrieve data from a table or to make calculations
are called select queries.
• Queries that add, change, or delete data are called action queries.
• You can also use a query to supply data for a form or report.
• In a well-designed database, the data that you want to present by using a
form or report is often located in several different tables.
• The tricky part of queries is that you must understand how to construct
one before you can actually use them.
Create Select Query
• If you want to review data from only certain fields in a table,
or review data from multiple tables simultaneously or maybe
just see the databased on certain criteria, you can use the
Select query. Let us now look into a simple example in which
we will create a simple query which will retrieve information
from tblEmployees table. Open the database and click on the
Create tab.
Click Query Design.
In the Tables tab, on the Show Table dialog,
double-click the tblEmployees table and then
Close the dialog box
• .
In the tblEmployees table, double-click all those fields
which you want to see as result of the query. Add these
fields to the query design grid as shown in the following
screenshot.
Now click Run on the Design tab,
then click Run.
• The query runs, and displays only data in those field
which is specified in the query.
MS Access - Query Criteria
• Query criteria helps you to retrieve specific items from an Access
database. If an item matches with all the criteria you enter, it
appears in the query results. When you want to limit the results
of a query based on the values in a field, you use query criteria.
• A query criterion is an expression that Access compares to query
field values to determine whether to include the record that
contains each value.
• Some criteria are simple, and use basic operators and constants.
Others are complex, and use functions, special operators, and
include field references.
• To add some criteria to a query, you must
open the query in the Design View.
• You then identify the fields for which you
want to specify criteria.
• Example
• Let’s look at a simple example in which we will
use criteria in a query. First open your Access
database and then go to the Create tab and
click on Query Design.
• In the Tables tab on Show Table dialog,
double-click on the tblEmployees table and
then close the dialog box.
• Let us now add some field to the query grid
such as EmployeeID, FirstName, LastName,
JobTitle and Email as shown in the following
screenshot.
Let us now run your query and you will see
only these fields as query result.
If you want to see only those whose JobTitle are Marketing
Coordinator then you will need to add the criteria for that. Let’s
go to the Query Design again and in Criteria row of JobTitle
enter Marketing Coordinator.
Let us now run your query again and you will
see that only Job title of Marketing Coordinators
are retrieved.
• If you want to add criteria for multiple fields,
just add the criteria in multiple fields. Let us
say we want to retrieve data only for
“Marketing Coordinator” and “Accounting
Assistant”; we can specify the OR row
operator as shown in the following screenshot
−
Let us now run your query again and you
will see the following results.
• If you need to use the functionality of the
AND operator, then you have to specify the
other condition in the Criteria row. Let us say
we want to retrieve all Accounting Assistants
but only those Marketing Coordinator titles
with “Pollard” as last name.
Let us now run your query again and
you will see the following results.
MS Access - Action Queries
• In MS Access and other DBMS systems,
queries can do a lot more than just displaying
data, but they can actually perform various
actions on the data in your database.
• Action queries are queries that can add,
change, or delete multiple records at one
time.
• The added benefit is that you can preview the
query results in Access before you run it.
• Action queries are queries that can add, change, or delete multiple
records at one time.
• The added benefit is that you can preview the query results in Access
before you run it.
• Microsoft Access provides 4 different types of Action Queries
• Append
• Update
• Delete
• Make-table
–
• An action query cannot be undone. You
should consider making a backup of any tables
that you will update by using an update query.
Create an Append Query
• You can use an Append Query to retrieve data from one or
more tables and add that data to another table. Let us create
a new table in which we will add data from the tblEmployees
table. This will be temporary table for demo purpose.
• Let us call it TempEmployees and this contains the fields as
shown in the following screenshot.
• In the Tables tab, on the Show Table dialog
box, double-click on the tblEmployees table
and then close the dialog box. Double-click on
the field you want to be displayed.
Let us run your query to display
the data first.
Now let us go back to Query design
and select the Append button.
In the Query Type, select the Append option
button. This will display the following dialog box.
• Select the table name from the drop-down list
and click Ok.
• In the Query grid, you can see that in the
Append To row all the field are selected by
default except Address1. This because that
Address1 field is not available in the
TempEmployee table. So, we need to select
the field from the drop-down list.
Let us look into the Address field.
Let us now run your query and you
will see the following confirmation
message.
• Click Yes to confirm your action.
• When you open the TempEmployee table, you will
see all the data is added from the tblEmployees to
the TempEmployee table.
MS Access - Relating Data
• Normalization
• Database normalization, or simply normalization, is the process
of organizing columns (attributes) and tables (relations) of a
relational database to minimize data redundancy. It is the
process of splitting data across multiple tables to improve
overall performance, integrity and longevity.
• Normalization is the process of organizing data in a database.
• This includes creating tables and establishing relationships
between those tables according to rules designed both to
protect the data and to make the database more flexible by
eliminating redundancy and inconsistent dependency.
• Let us now look into the following table which
contains data, but the problem is that this
data is quite redundant which increases the
chances of typo and inconsistent phrasing
during data entry.
CustID Name Address Cookie Quantity Price Total
12 Main St,
Ethel
1 Arlington, VA Chocolate Chip 5 $2.00 $10.00
Smith
22201 S
1234 Oak Dr.,
Tom
2 Pekin, IL Choc Chip 3 $2.00 $6.00
Wilber
61555
12 Main St.,
Ethil
3 Arlington, VA Chocolate Chip 5 $2.00 $10.00
Smithy
22201
• To solve this problem, we need to restructure
our data and break it down into multiple
tables to eliminate some of those redundancy
as shown in the following three tables.
• Here, we have one table for Customers, the
2nd one is for Orders and the 3rd one is for
Cookies.
• The problem here is that just by splitting the
data in multiple tables will not help to tell how
data from one table relates to data in another
table. To connect data in multiple tables, we
have to add foreign keys to the Orders table.
Defining Relationships
• A relationship works by matching data in key columns usually
columns with the same name in both the tables. In most
cases, the relationship matches the primary key from one
table, which provides a unique identifier for each row, with an
entry in the foreign key in the other table. There are three
types of relationships between tables. The type of
relationship that is created depends on how the related
columns are defined.
• Let us now look into the three types of relationships −
One-to-Many Relationships
• A one-to-many relationship is the most common type of
relationship. In this type of relationship, a row in table A can
have many matching rows in table B, but a row in table B can
have only one matching row in table A.
• For example, the Customers and Orders tables have a one-to-
many relationship: each customer can place many orders, but
each order comes from only one customer.
• Many-to-Many Relationships
• In a many-to-many relationship, a row in table A can have
many matching rows in table B, and vice versa.
• You create such a relationship by defining a third table, called
a junction table, whose primary key consists of the foreign
keys from both table A and table B.
• For example, the Customers table and the Cookies table have
a many-to-many relationship that is defined by a one-to-many
relationship from each of these tables to the Orders table.
One-to-One Relationships
• In a one-to-one relationship, a row in table A can have no more
than one matching row in table B, and vice versa. A one-to-one
relationship is created if both the related columns are primary
keys or have unique constraints.
• This type of relationship is not common because most information
related in this way would be all in one table. You might use a one-
to-one relationship to −
• Divide a table into many columns.
• Isolate part of a table for security reasons.
• Store data that is short-lived and could be easily deleted by simply
deleting the table.
• Store information that applies only to a subset of the main table.
Create Relationships
• we will understand the need to create relationships
between related tables. One of the goals of good
database design is to remove data redundancy.
• To achieve that goal, you divide your data into many
subject-based tables so that each fact is represented only
once.
• To do this, all the common fields which are related to
each other are placed in one table.
• To do this step correctly, you must first understand the
relationship between your tables, and then specify these
relationships in your Access database.
Why Create Table Relationships?
• MS Access uses table relationships to join tables when you
need to use them in a database object. There are several
reasons why you should create table relationships before you
create other database objects, such as forms, queries,
macros, and reports.
• To work with records from more than one table, you often
must create a query that joins the tables.
• The query works by matching the values in the primary key
field of the first table with a foreign key field in the second
table.
Why Create Table Relationships?
• When you design a form or report, MS Access uses the
information it gathers from the table relationships you have
already defined to present you with informed choices and to
prepopulate property settings with appropriate default
values.
• When you design a database, you divide your information
into tables, each of which has a primary key and then add
foreign keys to related tables that reference those primary
keys.
• These foreign key-primary key pairings form the basis for
table relationships and multi-table queries.
• Let us now add another table into your database and name it
tblHRData using Table Design as shown in the following
screenshot.
• Click on the Save icon as in the above
screenshot.
• Enter tblHRData as table name and click Ok.
tblHRData is now created with data in it.
One-To-One Relationship
• Let us now understand One-to-One
Relationship in MS Access. This relationship is
used to relate one record from one table to
one and only one record in another table.
• Let us now go to the Database Tools tab.
• Click on the Relationships option.
• To create a relationship between these two
tables, use the mouse, and click and hold the
EmployeeID field from tblEmployees and drag
and drop that field on the field we want to
relate by hovering the mouse right over
EmployeeID from tblHRData. When you
release your mouse button, Access will then
open the following window −
• The above window relates EmployeeID of
tblEmployees to EmployeeID of tblHRData. Let
us now click on the Create button and now
these two tables are related.
• The relationship is now saved automatically
and there's no real need to click on the Save
button. Now that we have the most basic of
relationships created, let us now go to the
table side to see what has happened with this
relationship.
• Let us open the tblEmployees table.
• Here, on the left-hand side of each and every
record, you will see a little plus sign by
default. When you create a relationship,
Access will automatically add a sub-datasheet
to that table.
Let us click on the plus sign and you will see the
information that is related to this record is on
the tblHRData table.
• Click on the Save icon and open tblHRData
and you will see that the data we have
entered is already here.
One-To-Many Relationship
• The vast majority of your relationships will
more than likely be this one to many
relationships where one record from a table
has the potential to be related to many
records in another table.
• The process to create one-to-many
relationship is exactly the same as for creating
a one-to-one relationship.
Let us first clear the layout by clicking on
the Clear Layout option on the Design tab.
We will first add another table tblTasks as
shown in the following screenshot.
Click on the Save icon and enter tblTasks as the
table name and go to the Relationship view.
Click on the Show Table option.
• We can run through the same process once
again to relate these tables. Click and hold
ProjectID from tblProjects and drag that all
the way over to the ProjectID from tblTasks.
Further, a relationships window pops up when
you release the mouse.
• Click the Create button. We now have a very
simple relationship created.
• MS Access - Form
Create Form
• Forms in Access are like display cases in stores
that make it easier to view or get the items
that you want. Since forms are objects
through which you or other users can add,
edit, or display the data stored in your Access
desktop database, the design of your form is
an important aspect. There's a lot you can do
design-wise with forms in Microsoft Access.
You can create two basic types of forms −
• Bound forms
• Unbound forms
Bound Forms
• Let us now understand what Bound Forms are −
– Bound forms are connected to some underlying data
source such as a table, query, or SQL statement.
– Bound forms are what people typically think of when
they think of the purpose of a form.
– Forms are to be filled out or used to enter or edit data
in a database.
– Examples of bound forms will typically be what users
use to enter, view or edit data in a database.
Unbound Forms
• Let us look into Unbound Forms −
– These forms are not connected to an
underlying record or data source.
– Unbound forms could be dialog boxes, switch
boards, or navigation forms.
– In other words, unbound forms are typically
used to navigate or interact with the
database at large, as opposed to the data
itself.
Types of Bound Forms
• There are many types of bound forms you can create in Access. Let
us understand the types −
• Single Item Form
This is the most popular one and this is where the records are
displayed — one record at a time.
• Multiple Item Form
This displays multiple records at a time from that bound data source.
• Split Form
The form is divided into halves, either vertically or horizontally. One
half displays a single item or record, and the other half displays a
list or provides a datasheet view of multiple records from the
underlying data source.
Creating Forms
• There are a few methods you can use to create forms in
Access. For this, open your Database and go to the Create
tab. In the Forms group, in the upper right-hand corner you
will see the Form Wizard button.
• Click on that button to launch the Form Wizard.
• On this first screen in the wizard, you can select fields
that you want to display on your form, and you can
choose from fields from more than one table or a query.
• Let us assume we want to simply have a quick form that
we are going to use for data entry for our employee
information.
• From Tables/Queries drop-down list, select
tblEmployees table. Click on the double arrow to move
all the fields at once.
Let us just leave it with that one
table, and click Next.
• The following screen in the Form Wizard will ask for the
layout that we would like for our form. We have columnar,
tabular, datasheet and justified layouts. We will choose the
columnar layout here and then click Next.
• In the following screen, we need to give a title for
our form. Let us call it frmEmployees.
• Once you have given your form a title, you can
open the form to see what that form looks like, or
you can begin entering information into your table.
Or
• you can choose the option to modify the form's
design. Let us choose the first option to open the
form to view or enter information and click Finish.
• Now, take a look at the following screenshot.
This is what your form looks like. This is a
single item form, meaning one record is
displayed at a time and further down you can
see the navigation buttons, which is telling us
that this is displaying the record 1 of 9. If you
click on that button then, it will move to the
next record.
• If you want to jump to the very last record in
that form or that table, you can use the
button right beside that right arrow, the arrow
with a line after it, that's the last record
button. If you want to add new employee
information, go to the end of this records and
then after 9 records you will see a blank form
where you can begin entering out the new
employee's information.
• This is one example of how you can create a form using
the Form Wizard. Let us now close this form and go to
the Create tab. Now we will create a slightly more
complicated form using Wizard. Click the Form Wizard
and this time, we will choose fields from a couple of
different tables.
• In this Form Wizard, let us choose tblProjects for
Tables/Queries, and select a few Available Fields such
as ProjectID, ProjectName, ProjectStart, and
ProjectEnd. These fields will now move to Selected
Fields.
• Now select tblTasks for Tables/Queries and
send over the TaskID, ProjectID, TaskTitle,
StartDate, DueDate and PercentComplete.
Click Next.
• Here, we want to retrieve data from a couple of
different objects. We can also choose from options
on how we want to arrange our form. If we want to
create a flat form, we can choose to arrange by
tblTasks, which will create that single form, with all
the fields laid out in flat view as shown above.
• However, if we want to create a hierarchical form
based on that one-to-many relationship, we can
choose to arrange our data by tblProjects.
• In the above window, we have the option to include a
subform for tblTasks, or we can make that a linked
form. This linked form is where tblProjects will have a
button that will launch that second form filtered to the
project that we have selected in that underlying
projects form. Let us now select the Form with
subform(s), and then click Next.
• In the following screen, you can choose a layout for
your subform. The Datasheet View gets selected by
default. The Datasheet View is similar to Table View.
Now, click Next.
• In the following screen, you need to provide a
name for your forms. Enter the name you
want and click Finish.
• Access will give you a preview of what your
form looks like. On top, you have the controls
on your main form, which is from our Projects
table. As you go down, you will see a subform.
It's like a form within a form.
• Multiple Item Form
• You may also want to create a specific kind of
form. For this, you can click on the More
Forms drop-down menu.
• From the menu, you can create a Multiple
Items form, a Datasheet form, a Split form, or
even a Modal Dialog form. These are typically
bound forms; select the object that you would
like to be bound to that form. This does not
apply to the Modal Dialog forms.
• To create this type of form, you will need to
select the object in navigation pane first. Let
us select tblEmployees here.
• The above step will further create a Multiple Items
form, listing out all the employees.
• Split Form
• This type of form is divided in equal halves, either
vertically or horizontally. One half displays a single
item or record, and the other half displays a list or a
datasheet view of multiple records from the
underlying data source.
• Let us now select tblEmployees in the navigation
pane and then on Create tab. Select Split Form
option from More Forms menu and you will see the
following form in which the form is divided vertically.
MS Access - Modify Form
• We have learnt several ways to create simple data entry
forms. Although the forms ease the process of data entry;
these may not serve other purposes that you would want.
They may not be catchy or user-friendly for what you
have intended.
• Upon creating a form, the first thing you will probably
want to do is resize or move the controls around.
• You might also need to add a control or remove a control.
• We will now discuss how to modify your form in an easy
way.
Controls
• It is merely a generic term used to describe
any object on a form or report that displays
data, performs actions or items used for
decorations such as a line. In other words, a
control is just about anything that is placed on
a form or report.
• The following can be considered as controls −
• Objects such as labels.
• Unbound or bound text boxes that you can use to add or edit
or even calculate an expression.
• Command buttons that perform actions like Save, Open an e-
mail or Print and these buttons are also known as controls.
• It is just a generic term for any object on a form or report.
• We will now look at the different aspects of making a form
presentable and understand how to edit and modify a form.
Let us now open our Multiple Items form which lists out all
employees from tnlEmployees.
• As you can see a list of employees, but doesn't
really look like a very user friendly list. Our
controls are oversized. They are too big,
spaced apart and do not provide a very useful
list view.
• To edit the appearance of your controls on
this form, you have two form views that you
can use. In the Home tab, click the View drop-
down.
• You have the Layout View or the Design View,
and both of these views are used to edit your
form. The Form View opens up by default; this
is the view you will use to interact with or edit
the underlying data source.
• To edit the appearance of the form itself, we
need to go to the Layout View first.
• When you switch to the Layout View, you will see a series of
contextual tabs appear.
• At the top of Access, you will see an area marked Form
Layout Tools with three tabs — Design tab, an Arrange tab,
and a Format tab and each of these tabs have different
options for formatting the look or appearance of the form.
• When you take your mouse and click on any one of these
controls, you will notice that Access will highlight a given area
of that form and all controls within that area are shaded a
light orange whereas the actual control that you select will be
shaded darker than the previous one or have a darker orange
border around where you click.
Here you can resize your controls as you want
by clicking and dragging your mouse to resize
the height or width or both of that one control.
On this particular form, when you resize any
single control, you also change the size of the
rest of your controls on your form, this is
because of how these controls are grouped. Let
us now adjust all the fields the way you want by
using the click and drag function of the mouse.
That is one quick way of editing the
height and width of controls in your
form from this Layout View.
• Themes
In Access, there are some basic ways to format
your forms by using built-in themes, colors, and
font styles, customizing fill colors and shading
alternate rows. Let us now open frmEmployees.
• The forms that Access creates are plain and
simple. They have a blue bar on the top and a
white background.
• If you want to see how else you can stylize
these forms, you can go to the Design View or
Layout View and explore some of the options
you have on the Design tab in the Themes
area.
• If you click on the Themes' drop-down gallery,
you have many pre-created themes to try out
from. Hovering your mouse over any one of
them will give you a preview of changing
things like colors and font sizes and the actual
font used. To apply a particular style, simply
click your mouse on it and you can see what
that looks like.
• If you like the theme but you want to change
the colors, you can adjust the colors by going
back to the Themes group on the Design tab
and choosing the color you like. You can also
create custom colors to match your
company's colors.
• Similarly, you also have a series of font styles
to choose from. You can choose one from the
many that come prebuilt with the Office Suite
or you can customize those fonts, choosing a
specific heading font, a body font and even
creating a custom name for that font group
and saving.
Let us go back to frmEmployees. In this form, you will see that
every alternate row is shaded light gray.
The formatting option is referred to as Alternate Row Color and if
you want to adjust that in a multiple form, go to the Design View.
Select that detail section and then go to the Format tab and in
background group you should see an option for Alternate Row
Color. You can change the colors for alternate rows. To see what
that looks like, simply go to the Form View or the Layout View.
If you don't want any shading at all, you can choose No
Color as your Alternate Row Color and that is more the
traditional look from earlier versions of Access.
Reports Basics
Reports Basics
• In this chapter, we will be covering the basics
of reports and how to create reports. Reports
offer a way to view, format, and summarize
the information in your Microsoft Access
database. For example, you can create a
simple report of phone numbers for all your
contacts.
Reports Basics
• A report consists of information that is pulled from tables or
queries, as well as information that is stored with the report
design, such as labels, headings, and graphics.
• The tables or queries that provide the underlying data are
also known as the report's record source.
• If the fields that you want to include all exist in a single table,
use that table as the record source.
• If the fields are contained in more than one table, you need to
use one or more queries as the record source.
• Example
• We will now take a simple example to
understand the process of creating a very
simple report. For this, we need to go to the
Create tab.
• Before clicking on the Report button to create
a basic report, make sure the proper query is
selected. In this case, qryCurrentProjects is
selected in your navigation pane. Now click on
the Report button, which will generate a
report based on that query.
• You will see that the report is open in Layout
view. This provides a quick way to adjust the
size or width of any of your fields that you see
on the report. Let us now adjust the column
widths to make everything fit in a better way.
Scroll down and adjust the page
control at the bottom.
This was a very quick way to create a very simple
report. You could also make minor changes and
adjustments from the report design view.
• Just like forms, a report is made up of a variety of
different sections.
• You have the detail section, which is where all of
your data lives for the most part.
• You also will see a page header and a page footer
section; these appear at the top and at the bottom of
every single page in your report.
• Let us now change the Title of the report and give it
another name.
• Click on the save icon to save your report.
• You will get the above dialog box.
• Enter a name for your report and click Ok. If you want to view
what this report will actually look like, in Print Preview, you
can go back to the View button and click on Print Preview to
see what this report would look like when printed either on
paper or as a PDF.
• Enter a name for your report and click Ok. If
you want to view what this report will actually
look like, in Print Preview, you can go back to
the View button and click on Print Preview to
see what this report would look like when
printed either on paper or as a PDF.