0% found this document useful (0 votes)
17 views105 pages

Access

Uploaded by

Abebe Dejene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views105 pages

Access

Uploaded by

Abebe Dejene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 105

Well Come

Database Management
System
 Before defining Database
Management System (DBMS), it
is better to define the following
terminologies first.
• Data
• Information
• Database
DBMS

Data
 Data is a Collection of facts made up of text,
numbers, dates & etc
• Data can be defined as unprocessed information.

Information
 Information is the meaning given to data in the
way it is interpreted and is used to make decision
• Information is data that have been organized and
communicated in a accurate and meaningful
manner.
Cont…

• Data is converted into information, and


information is converted into
knowledge.
• Knowledge is evaluated and organized
information ,so that it can be used
purposefully

Data Information Knowledge Action


DBMS

Database
 A database is a collection of logically related

data (and a description of this data),


designed to meet needs of an organization.
 A database is also a collection of related

information.
Database Management System (DBMS)
 DBMS is thus, a software that enables users

to define, create and maintain the database


and provides controlled access to the
database.
Traditional approach

 Applications developed in an ad-hoc and


opportunistic manner
 Data requirements for applications
derived independently
 Data files developed for individual
applications
 Application programs are data
dependent
Files dedicated to application
programs
Drawbacks of using file
systems to store data:
 Data redundancy and inconsistency
 Multiplefile formats, duplication of information in
different files
 Difficulty in accessing data
 Need to write a new program to carry out each new
task
 Data isolation — multiple files and formats
 Integrity problems
 Integrityconstraints (e.g. account balance > 0)
become part of program code
 Hard to add new constraints or change existing
ones
Drawbacks of using file
systems (cont.)
 Atomicity of updates
 Failures may leave database in an inconsistent state
with partial updates carried out
 E.g. transfer of funds from one account to another
should either complete or not happen at all
 Concurrent access by multiple users
 Concurrent accessed needed for performance
 Uncontrolled concurrent accesses can lead to
inconsistencies
 E.g. two people reading a balance and updating it at the
same time
 Security problems
 Database systems offer solutions to all the
above problems
Database Approach

 Centralization of information
management
 Data shared by different groups of users
and application programs
 Provision of multiple interfaces
 Representation of complex relationships
between data
 Integrity constraint handling
 Advanced facilities for backup and
recovery
Data Sharing in a Database
Environment
Cont…
Advantage of database

 Sharing of data
 Enforcement of security
 Enforcement of development and
 maintenance standards
 Reduction of redundancy
 Avoidance of inconsistency across files
 Maintenance of integrity
 Data independence
Functions DBMS

 Data storage, retrieval, update


 A user-accessible catalog
 Transaction support
 Concurrency control
 Recovery services
 Authorization services
 Integrity services
 Data independence
 Utility services
Cont…

 The database should contain all the


data needed by the organization.
– The set of facts represented in a
database is called the Universe of
Discourse (UOD).
– The UOD should only include facts that
are relevant to its users.
– A database should always be designed,
built and populated for a particular
audience for a specific purpose.
Cont…

 Emphasis is on the relevant data


pertaining to one or more objects
or entities.
– Entity: a thing of significance
about which information needs to
be known.
 The characteristics that describe or

qualify an entity are called


attributes of the entity.
Cont…

 For example:
– In a student database, the basic entity is
the student.
– Entity attributes (information recorded
about that entity) may include:
 First and last name
 Grade point average
 Home address
 Current address
 Date of birth
 Course opted
Cont…

 The system would not be interested


in
– the type of clothes
– the number of friends
– the movies the student attends
– etc.
 This information is not relevant to
the user and should not be part of
the UOD.
Cont…

 For each attribute, the set of possible values


that the attribute can take is called the
domain of the attribute.
– The domain of the date of birth would be all
the dates that might be reasonable in the
student body.
– Undergraduate class levels would probably be
restricted to
 Part I
 Part II
 Part III
 No other values would be allowed.
Users
 There are a number of users who can access or
retrieve data on demand using the applications
and interfaces provided by the DBMS. Each
type of user needs different software
capabilities:
– The database administrator (DBA) is the person
or group in charge of implementing the database
system within the organization.
– The end users are the people who sit at
workstations and interact directly with the system.
– The application programmers interact with the
database by accessing the data from programs
written in high-level languages such as Visual Basic
or C++.
RDBMS

 Is a database management system that depends


on the relational database model.
 A major feature of relational databases is to
combine (join) tuples stored in different tables in
order to display more meaningful and complete
information.
 RDBMS allows operations in a human logical
environment.
 The relational database is perceived as a
collection of tables. Each table consists of a series
of row/column intersections.
 Tables (or relations) are related to each other by
sharing a common entity characteristic(attribute).
Cont…

Advantages:
 Improved conceptual simplicity

 Easier database design, implementation,

management, and use Ad hoc query


capability (SQL)
 Powerful database management system
Cont…

Disadvantages:
– Relational databases do not
have enough storage area to
handle data such as images,
digital and audio/video.
In a RDBMS,

 We will use the terms tables and


relations interchangeably.
 data is logically perceived as tables.
 Tables are logical data structures that
we assume hold the data that the
database intends to represent.
 Tables are not physical structures.
 Each table has a unique name.
Cont…

 Tables consist of a given number of columns


or attributes.
 Every column of a table must have a name.
 No two columns of the same table may have
identical names.
 The total number of columns or attributes
that comprises a table is known as the
degree of the table.
 In this class, we use the terms column and
attribute interchangeably.
Cont…

 The data in the table appears as a set of


rows or n-tuples, Where n is the number of
attributes of the table.
 Whenever the number of attributes of the
table is understood, we can omit the prefix
n and refer to the rows of the table as just
rows or tuples.
 All rows of a table have the same format
and represent some object or relationship
in the real world.
Cont…

 The total number of rows present in


a table at any one time is known as
the cardinality of the table.
– In legacy systems, the terms field
and record are used as synonyms of
the terms attribute and row
respectively.
 In this class, row, record and tuples

are used interchangeably


Cont…

 In general, when tables are defined, the


number of columns remain fixed for the
duration of the table, however, the number of
rows present in the table is bound to vary
 Tables are required to have at least one
column.
 Tables are not required to have rows.
 A table with no rows is called an empty table.
 The process of inserting tuples for the very
first time into a table is called populating the
table.
Cont…

 Whenever a relation is represented


by means of a table, we will assume
the following conditions hold:
 The table has a unique name
 Each column of the table has a unique name.
 No two columns of the same table may have
identical names
 The order of the columns within the table is
irrelevant
 All rows of the table have the same format and
the same number of entries.
Cont…

 The values under each column belong to


the same domain
 Strings of characters
 Integer values
 Real values
 Etc.
 Every entry (the intersection of a row
and column) of every tuples of the
relation must be a single value
 No list or collection of values is allowed
Candidate Key and Primary Key of
a Relation

 The notion of a key is a fundamental concept


in the relational model Provides the basic
mechanism for retrieving tuples within any
table of the database.
 To distinguish a candidate key
 No two different tuples of the relation will
have identical entries in all attributes of the
key
 The number of attributes that comprises the
key must be minimal
Cont…
 Since a relation may have more than one
candidate key, one of these candidate keys
should be designated as the primary key (PK)
of the relation.
 The values of the primary key can be used as
the identification and addressing mechanism
of the relation.
 We will differentiate between the different
rows of the relation on the basis of their PK
values.
 We will also uniquely retrieve tuples from a
relation based on the values of their PK values.
Cont…

 Once a primary key has been selected,


the remaining candidate keys, if they exist
are called alternate keys.
 A RDBMS allows only one primary key per
table.
 A primary key may be composed of a
single attribute (single primary key) or
more than one attribute (composite
primary key)
Cont..

 Since the primary key is used to identify the


tuples or rows of a relation, none of its
attributes may be NULL.
– In a relation, the NULL value is used to
represent missing information, unknown, or
inapplicable data.
 A NULL value is not a zero value

 A NULL value doesn’t represent a particular

value within the computer.


 This imposes an additional condition or

constraint on the keys known as the integrity


Foreign key

 Because columns that have the same


underlying domain can be used to relate
tables of a database, the concept of foreign
key (FK) allows the DBMS to maintain
consistency among the rows of two relations
or between the rows of the same relation.
 The attributes of a FK have the same underlying
domain as the set of attributes defined for the
PK.
 The FK values in any tuple of a relation are
either NULL or must appear as the PK values of a
tuple of the corresponding relation.
Cont…

 The table that contains the foreign key


is the child table
 The table that contains the referenced

attribute(s) is the parent table.


 The FK value in each row of a child

table is either NULL or Must match the


PK value of a tuple of the parent table.
Cont…

 Foreign keys are usually defined after


all the tables have been created and
populated.
 Avoids the problem of circularity:

 Occurs when one table references

values in another table, which in turn


may reference the first table.
 Integrity constraints are automatically

enforced by the RDBMS.


Database Elements

 Table
 Queries
 Forms
 Reports
 Macros
 Modules
 Pages
Description of db
elements
Tables
 Tables are the key part of the database,
that are used to store all the information
that is contained in the database.
Queries
 Queries are the questions that you ask your
database about the data stored in it.
Forms
 Forms are used to provide an easy way to
view or enter data into the database.
Cont…

Reports
 Reports are used to print out data from your
database. You can print out Tables and
Queries as well, but Reports can be
formatted to produce more professional
looking documentation.
Pages
 Pages are Internet/Intranet Forms. They
can be used to input data into an Access
database via the Internet (or Intranet) using
a web browser such as Microsoft Explorer.
Cont…
 Macros
 Macros are an advanced way of automating
common tasks in the database.
 Modules
 Modules are an advanced way of
automating common tasks in the database
using Visual Basic programming.
DBMS Tools
 MS Access
 MySQL Se le
 MS SQL cted
to b
 Oracle e us
 DB2 ed
 Postgre
 & etc
Starting MS Access
2007
Introduction
 A database is a collection of information

that's related.
 Access allows you to manage your

information in one database file. Within


Access there are the following areas:
Tables, Queries, Forms and Reports,
Macros, Modules and Pages
Cont…

 Among these areas, the following ones


were selected for further study in this
section because they are frequently
used and applicable here.
 Table
 Queries
 Forms
 Reports
Table

• Tables are the key part of the


database, that are used to store all the
information that is contained in the
database.
• Table is a building block of any
database
• Tables store your data in your
database
Creating and Designing a
Database
1) Creating Tables
Cont…

 Select Blank Database


 In the File Name field enter a name for
the database
 Click Create
 Microsoft Access automatically creates a
new table in the database called
Table1. This is a temporary name
until the table is saved and is shown
below.
Understanding the Views

 There are 2 basic views when you work


in a table:
 Design View and
 Datasheet View
 Design View is used to set the data
types, insert or delete fields, and set
the Primary key. Datasheet View is used
to enter the data for the records. By
default, Access places you in Datasheet
View.
Cont…

To Switch to Design view:


1)Click the View button on the Home
Ribbon
2) Type a name for the table
3) Click OK
Before proceeding, it is important to
understand common Microsoft Access Data
Types.
To Enter Fields in a Table:

1) Type a name for the first field in the table


2) Press Enter
3) Select a data type, Press Enter
4) Type a description for the field, Press Enter
and Continue this until all necessary fields
have been entered into the table.
Note: The order that you enter the field
names is the order the fields will
appear in the table and on a form.
Setting a Primary Key

 The Primary Key is the unique


identifier for each record in a table.
Access will not allow duplicate entries
in a Primary Key field. By default, Access
sets the first field in the table as the
Primary Key field.
 An example of a Primary Key would be
your Social Security Number. This is
something unique about you and should
not be duplicated.
To Set a Primary Key:

1) Switch to Design View


2) Position your cursor in the field you wish
to set as the Primary Key
3) Click the Primary Key button on the
Ribbon as shown below
A Table Relationship
 After you have created a table for each subject
in your database, you must provide the means
by which to bring that information back
together again when needed.
 You do this by placing common fields in tables
that are related, and by defining relationships
between your tables.
 You can then create queries, forms, and
reports that display information from several
tables at once.
 For example, have a look at the following form
Cont…
1) Information in this form comes from the Customers
table...
2) ...the Orders table...
3) ...the Products table...
4) ...and the Order Details table.
 The customer name in the Bill To box is retrieved

from the Customers table, the Order ID and the


Order Date values come from the Orders table,
the Product name comes from the Products
table, and the Unit Price and Quantity values
come from the Order Details table. These tables
are linked to each other in a variety of ways to
bring information from each into the form.
Cont…
 For example, employees can be
associated with orders for which they are
responsible by creating a table
relationship between the EmployeeID
fields in the Employees and the Orders
tables.
Types of table
relationships
 There are three types of table relationships.
 A one-to-many relationship : Consider an order
tracking database that includes a Customers table and
an Orders table. A customer can place any number of
orders. It follows that for any customer represented in
the Customers table, there can be many orders
represented in the Orders table. The relationship
between the Customers table and the Orders table is,
therefore, a one-to-many relationship.
 To represent a one-to-many relationship in your
database design, take the primary key on the "one" side
of the relationship and add it as an additional field or
fields to the table on the "many" side of the
relationship.
A many-to-many
relationship
 Consider the relationship between a Products
table and an Orders table.
 A single order can include more than one product.
 On the other hand, a single product can appear on
many orders.
 Therefore, for each record in the Orders table, there
can be many records in the Products table. In
addition, for each record in the Products table, there
can be many records in the Orders table. This type
of relationship is called a many-to-many relationship
because, for any product, there can be many orders
and, for any order, there can be many products.
Cont…
 To represent a many-to-many relationship, you must
create a third table, often called a junction table, that
breaks down the many-to-many relationship into two
one-to-many relationships.
 You insert the primary key from each of the two tables
into the third table.
 As a result, the third table records each occurrence, or
instance, of the relationship.
 For
example, the Orders table and the Products table have a
many-to-many relationship that is defined by creating two one-to-
many relationships to the Order Details table. One order can have
many products, and each product can appear on many orders.
A one-to-one relationship
 In a one-to-one relationship, each record in the first
table can have only one matching record in the
second table, and each record in the second table
can have only one matching record in the first table.
This type of relationship is not common because,
most often, the information related in this way is
stored in the same table. You might use a one-to-one
relationship to divide a table with many fields, to
isolate part of a table for security reasons, or to store
information that applies only to a subset of the main
table. When you do identify such a relationship, both
tables must share a common field.
Creating Relationship
 we can create a table relationship in the
Relationships window
 When we create a relationship between
tables, the common fields are required to
have the same data type, and the equal size
also. They can have different names for their
fields
 E.g. If the primary key field in one table is an
AutoNumber field, the foreign key field can
also be a Number field if the Field Size
property of both fields is the same.
To create a relationship:
 Click the Microsoft Office Button
, and then click Open.
 In the Open dialog box, select and open
the database.
 On the Database Tools tab, in the
Show/Hide group, click Relationships.
Cont…
 If you have not yet defined any
relationships, the Show Table dialog
box automatically appears. If it does not
appear, on the Design tab, in the
Relationships group, click Show
Table.
Cont…
 The Show Table dialog box displays all
of the tables and queries in the
database.
 To see only tables, click Tables.
 To see only queries, click Queries.
 To see both, click Both.

 Select one or more tables or queries and


then click Add. After you have finished
adding tables and queries to the
Relationships document tab, click Close.
Cont…
 Drag a field (typically the primary key) from
one table to the common field (the foreign
key) in the other table.
 The edit relationship dialog box appears as
follows
Cont…
 Verify that the field names shown are the common
fields for the tables. If a field name is incorrect, click
on the field name and select the appropriate field from
the list.
 To enforce referential integrity for this relationship,
select the Enforce Referential Integrity check box.
 The purpose of referential integrity is to to prevent orphan
records(records without reference) and to keep references
synchronized so that you don't have any records that reference
other records that no longer exist.
 Once enforced, Access rejects any operation that would violate
referential integrity for that table relationship. This means that
Access will reject both updates that change the target of a
reference and deletions that remove the target of a reference.
Cont…
Then Click Create.
 Access draws a relationship line between the two

tables.
 If you selected the Enforce Referential Integrity

check box, the line appears thicker at each end.


 In addition, again only if you selected the Enforce

Referential Integrity check box, the number 1


appears over the thick portion on one side of the
relationship line, and the infinity symbol (∞) appears
over the thick portion on the other side of the line, as
shown in the following figure.
Cont…
Cont…
 To create a one-to-one
relationship, Both of the common fields
(typically the primary key and foreign key
fields) must have a unique index. This
means that the Indexed property for these
fields should be set to Yes (No
Duplicates). If both fields have a unique
index, Access creates a one-to-one
relationship.
Cont…
 To create a one-to-many relationship, The
field on the one side (typically the primary key)
of the relationship must have a unique index.
This means that the Indexed property for this
field should be set to Yes (No Duplicates).
 The field on the many side should not have a
unique index. It can have an index, but it must
allow duplicates. This means that the Indexed
property for this field should be set to either
No or Yes (Duplicates OK). When one field
has a unique index, and the other does not,
Access creates a one-to-many relationship.
Cont…

 Do the same thing for the rest of


the tables as need and proceed to
enter data in to the tables
 Once you have created the

tables, entered the fields and set


the data types and primary key,
set the relation ships between
tables, it is now time to enter the
records in a table.
Entering Data in a Table

To Enter Data in a Table:


 1) Make sure you are in Datasheet View(default)

 2) Enter the data into the table by pressing the

tab key to move from one cell(field) to another


 3) When you have completed the record (row),

press Enter
Creating A New Record
 Click on the "New" button
 You will be moved to the empty row at the bottom of the
table.
 You can use the [Tab] key to move through the fields in
the row.
 Type in the new data
When inputting data into the table, Access
automatically saves the data after each new
record.
Navigating Records

 Use the arrows at the bottom of the


table to navigate among records.
 You are able to navigate from the first
record, previous record, next record, last
record, and create a new record (as
shown in the picture below).
 Notice that the total number of records
in the table is shown at the right end of
the navigation arrows.
Navigation Commands

 There are some keyboard navigation


commands that can be used to move around
the table.
 [Tab]
 Moves you to the next field
 [Shift]+[Tab]
 Moves you to the previous field
 [Home]
 Moves you to the first field in the current record
 [End]
Continued…
 Moves you to the last field in the current
record
 Arrow Keys
 Move you up, down, left and right by one field
 [Ctrl]+[Home]
 Moves you to the very first field in the table
 [Ctrl]+[End]
 Moves you to the very last field in the table
 [Page Up]
 Moves you one screen view up the table
Continued…
 [Page Down]
 Moves you one screen view down the table
 [Ctrl]+[+]
 Moves you to the new blank record at the
bottom of the table
Selecting data
 You can select fields, records and
columns in any table.
 The Field Headings are used to select
columns. The Record Selectors are used
to select records
These are the techniques for
selecting data:
Editing records
 To Edit An Existing Record
 Click in the field you wish to edit, to insert
the flashing Text Insertion Point
 You can then use the [Backspace] key to
delete text to the left of the flashing line, or
the [Delete] key to delete text to the right
of the flashing line. You can also use the left
and right arrow keys to move left and right,
one character at a time, through the text.
 Type in the appropriate changes
To Delete A Record
 You cannot always delete records in a table.
It depends on how the table was set up, or
whether old data is kept for archiving
purposes. Ask the owner of your database
if you should delete records.
 Select the record
 In the “Edit” menu, select “Delete” or
press the [Delete] key
 A dialog box will appear, asking you if you
are sure you wish to delete the record.
Hiding, Showing and resizing
Columns
 To Hide A Column(s)
 Select the column(s)
 Right click on selected column  “ Hide
Columns "
 The selected columns will now be hidden.
 To Unhide Hidden Columns
 Right click on any column "Unhide Columns"
 The Unhide Columns dialog box will appear.
This contains a list of all your column headings.
The column headings without a tick by them
are not showing in the table.
Continued…
 Click on the box next to the Column Heading
to add a tick
 Repeat for each column you wish to unhide,
then click on the "Close" button
 TO RESIZE A COLUMN
 Columns are resized using the right side of the
column selectors, at the top of the column.
 Position the cursor at the right side of the
column selector for the column you wish to
resize
 Click and drag to the right to increase the
width, or to the left to decrease the width
Continued…
 To Move A Column
 You can change the order of the columns in
a table.
 Click on the column selector to select the
column (and then release the mouse
button)
 Click and drag on the column selector to
move the column
Continued…
 To Print The Whole Table
 Click on the "Print" button
 To Print Part Of The Table
 Select the fields, records or columns that
you want to print.
 In the “File” menu, select “Print”
 The Print dialog box will appear.
 You can use the Print Range options to
control how much of the table is printed:
Continued…
 All - prints the whole table
 Selection - prints just the selected records
or columns
 Pages - allows you to specify a range of
pages if the table is too big to fit on one
page
 Select the appropriate Print Range
 Click "OK"
Copying Data To Word
 Use the Record Selectors or the Field
Selectors to select the rows or columns
you wish to copy
 Click on the “Copy” button
 Open Word
 In Word.
 Click in the document text to choose the
insertion point
 Click on the “Paste” button
 The data will be pasted into your document
as a Word table.
Copying Data To Excel

 In your Access table.


 Use the Record Selectors or the Field
Selectors to select the rows or columns
you wish to copy
 Click on the “Copy” button
 Open Excel
 In Excel.
 Click in the spreadsheet to choose the
insertion point
 Click on the “Paste” button
 The data will be pasted into your spreadsheet
Finding data
 To Find Data
 If you know which field contains the data
you wish to search for, and you wish to
search the whole column from the top.
 Click in the first cell in the column you
wish to search
 Click on the "Find" button
 The Find dialog box will appear.
 In the Find What box, enter the text you
wish to find
Queries

 Queries are the questions that you ask


your database about the data stored in it.
A query is a set of instructions that
you can use for working with data.
You run a query to perform these
instructions.
 In addition to returning results —

which can be sorted, grouped, or


filtered — a query can also create,
copy, delete, or change data.
Types of queries
 Select query
 Update query

 Make table query

 Append query
Select query
 A select query is a type of database object that
shows information in Datasheet view (Datasheet
view: A window that displays data from a table,
form, query, view, or stored procedure in a row-and-
column format.
 In Datasheet view, you can edit fields, add and
delete data, and search for data). A query can get
its data from one or more tables, from existing
queries, or from a combination of the two. The
tables or queries from which a query gets its data
are referred to as its record source. we can create
this query either in Design view or by using a wizard
Update query
 You use update queries to add, change, or delete the
data in one or more existing records. You can think
of update queries as a powerful form of the Find
and Replace dialog box. You enter a select criterion
(the rough equivalent of a search string) and an
update criterion (the rough equivalent of a
replacement string).
 Unlike the Find and Replace dialog box, update
queries can accept multiple criteria, allow you to
update a large number of records in one pass, and
allow you to change records in more than one table
at one time.
Append query
 This article explains how to create and run an
append query.
 You use an append query when you need to add
new rows of data to an existing table.
 If you need to change or update part of the data in
an existing set of records, such as one or more
fields, you can use an update query.
 The process of creating an append query follows
these basic steps:
 Create a select query.
 Convert the select query to an append query.
 Choose the destination fields for each column in the
append query. Run the query to append the records.
Make a table query
 A make table query retrieves data from one or
more tables, and then loads the result set into a
new table.
 That new table can reside in the database that
you have open, or you can create it in another
database.
 Typically, you create make table queries when
you need to copy or archive data.
 To create such a query, in query Design view,
create a select query and then modify that query
until it returns the records you want. You can
select data from more than one table and, in a
real sense, you can de-normalize your data.

You might also like