0% found this document useful (0 votes)
57 views66 pages

Understanding Databases and MS Access

Uploaded by

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

Understanding Databases and MS Access

Uploaded by

CapturedSkull
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1

DATABASE (ACCESS)

DR. SAMAR A. SAID


First term
2023-2024
POINTS TO BE COVERED:
• Database concept

• Microsoft access

2
WHY DATABASE???

• Traditionally, data was organized in file formats.

• Database system is a new concept that overcomes the deficiencies


in traditional style of data management.

3
Traditional file system
• What are traditional file systems?
• Traditional file based system is basically a file based system, in which we
manually handle the database such as updating, inserting, deletion or
adding new files to database, etc. Disadvantages
Advantages
• Provide less security.
• Redundancy is high.
• Less integrity High (Inconsistency
).
• Complexity in updating of
• No need of highly
database records.
technical person to
• Processing speed is low.
handle the database.
• Concurrent access of data is not
achievable.
• Difficulties on providing backup
4
and recovery.
FILE SYSTEM VERSUS DBMS

5
WHAT IS DATABASE????
• What is the data ?, and what are the Database that use this
data ?
• Data are known facts that can be recorded and have implicit
meaning.

• Database is a collection of related data.

• Example: telephone directory(name, tel., Address) is a simple form


of database

6
WHAT IS DBMS?
• The collection of programs that enables users to create and maintain a
database system is called database management system DBMS.

• Database management system in short refers to the technology of storing


and retrieving users data with utmost efficiency along with appropriate
security measures.

7
EXAMPLE OF DATABASE
(UNIVERSITY DATABASE)

• The aim (objective) is to maintain information concerning


students, courses, and grades in a university.

• The structure of the database is organized in different files,


there are four files{student file, course file, section file,
grade_report file}

8
EXAMPLE OF DATABASE
(UNIVERSITY DATABASE)

9
EXAMPLE OF DATABASE
(UNIVERSITY DATABASE)

10
EXAMPLE OF DATABASE
(UNIVERSITY DATABASE)

• As you can notice that the course number field in section file is
similar to course number in course file.

• So, in this way you can create a link between different files or
link between data in our database.

11
DEFINING A DATABASE
(UNIVERSITY DATABASE)
• Defining a database

• Defining a database means:

• Specify the different types of data elements to be stored in each


record.

12
DEFINING A DATABASE
(UNIVERSITY DATABASE)

13
DEFINING A DATABASE
(UNIVERSITY DATABASE)
• Of course, this definition is not complete because you have to
define:

•The type of each element in each field.


{ Name as string, student id as numerical value}

•Constraints
{1 up to 4, no negatives, no values more than 5 or 6}

14
CONSTRUCTING A
DATABASE

• Store data to represent each student, course, section, and


grade_report as a record in appropriate file.

• Records stored in these different files can be related with each


other.

15
CONSTRUCTING A
DATABASE
(UNIVERSITY DATABASE)

16
MANIPULATING A
DATABASE

• Which is querying and updating a database:

• Examples:
•List the names of students who took the interactive multimedia
course offered in fall 2000 and their grades. (Querying)

•Create a new section for the network multimedia course for this
semester. (inserting)

17
UNIVERSITY DATABASE

• What we did in university-db is

• Defining a database

• Constructing database

• Manipulating database

18
MICROSOFT ACCESS
Microsoft Access- An Overview

• Microsoft Access also known as Microsoft Office Access is a


Database Management System or DBMS from Microsoft.

• It helps us manage data stored in a computer database. A


Database is a tool for collecting and organizing information.
Database can store information about people, products,
orders, or anything else.
Using Access, we can do the following :
• Add new data to a database, such as a new item in an
inventory
• Edit existing data in the database, such as changing the
current location of an item
• Organize and view the data in different ways

●An Access database stores its tables in a single file, along with
other objects, such as forms and reports

●Databases created in the Access format have the file extension


.accdb, and databases created in earlier Access formats have
the file extension .mdb.
DATA SHEET VIEW
Datasheet View

Datasheet View : A view that displays data from a


table, form, query, or view in a row-and-column
format.

In Datasheet view, you can edit fields, add and delete


data, and search for data.
Create a table in Datasheet view
Datasheet view
provides a visual way to
create a table.
Start by creating a new,
blank database or by
adding a new table to an
existing database. Either
method opens a new
table in Datasheet view.
Notice that the new table
The process, in Datasheet view. contains a field called ID.
That’s your primary key,
so you don’t need to
create one.
Datasheet view
provides a visual way to
create a table.
To add your fields, click
the first blank field
header – the words
Click to Add. That starts
a menu of data types,
and you select a data
type for the field. After
that, the field header
then becomes available
for writing, so...

The process, in Datasheet view.


Datasheet view
provides a visual way to
create a table.
When you’ve finished,
press CTRL+S, or go to
the Quick Access
Toolbar and click Save.
That starts a Save As
dialog box, where you
enter a name for the
table and then save it.

The process, in Datasheet view.


Design View

Design view:
In Design view, you can create new database objects
and modify the design of existing objects.
Create a table in Design view
Design view allows you
to build a table from
scratch and set or
change every available
property for each field.

You can also open existing tables in Design view


and add, remove, or change fields.

Using Design view.


On the Create tab, in the
Tables group, click
Table Design.
In the Field Name
column of the designer,
enter the names of your
table fields. As a rule,
the first field you create
should be your primary
key field. And remember
that you don’t need to
add any foreign key
fields now. You can do
that when you create
your relationships.
Using Design view.
In the Data Type
column, use the list next
to a field name to
choose a data type for
that field.

Optionally, use the Field


Properties pane to set
properties for individual
fields.

As always, save your changes and give your new


table a name that describes the data it contains.

Using Design view.


A characteristic of a field
that determines what kind
of data it can store.

For example: a field whose data type is Text can store


data consisting of either text or numeric characters, but a
Number field can store only numerical data.
Example
Creating a order table

• Ahmed wants to track information about each order placed


by each restaurant customer. This information includes the
order’s billing date and invoice amount. Ahmed asks you to
create a table in the restaurant database, named order, in
which to store the order data.
CREATING AN ORDER TABLE

• Use design view


• Exact match of each name
• Use tap key to enter data
• Especially, when you enter data in datasheet view.
CREATING THE ORDER TABLE

Field Name Data Type Description Field Properties

OrderNum Text primary key Field size (3), Required (Yes)

CustomerNum Text foreign key Field size (3)

BillingDate Date/Time

PlacedBy Text person who Field size (25)


placed order

InvoiceAmt Currency
ADDING RECORDS TO A TABLE

• Enter data sequentially in datasheet view


• Do not jump from field to field
• Use tap key to enter data

OrderNum CustomerNum BillingDate PlacedBy InvoiceAmt


323 624 02/15/2001 Mike Smith $1,986.00
201 107 01/15/2001 Matt Davis $854.00
MODIFYING A TABLE

• From the order table


• Delete the placedby field
• Move the billingdate field to the end of the table
• Insert the paid as a new field between customernum and invoiceamt
(position) fields
• Data type: yes/no
• Default value: no (means “unpaid”)
• Add following data to each filed: 211, 201, paid (mark the check box
using space bar), $703.50, 01/15/2001
THE ORDER TABLE

38
EMPLOYEE TABLE

39
CUSTOMER TABLE

40
CHARACTERISTICS OF
RELATIONAL DB

• In a relational database, each record (row) in a table must be


uniquely identified.
• Using primary key

• A relational database is a collection of tables that are related to


one another based on a common field.
• Using foreign key (& primary key)
PRIMARY KEY (PK) & FOREIGN
KEY (FK)
• PK: A field that uniquely identifies each record in a table.
• CustomerID, OrderID, EmployeeID
• It does not have to be first field.

• Fk: a field that connects one table logically with another


table
• Rule of thumb: pk = fk (value)
DATA INTEGRITY (PK RULE)

• No “null” value can be allowed.


• Unique, no two records can have the same primary key.
• No two orders can have same id number.
Referential integrity (FK rule)

• A field that connects one table logically with another


table.
• “Pk as fk” there are two tables…
• Primary table: CustomerID
• Related table: Order table (CustomerID)
RELATING TABLES USING PK AND
FK
The primary key in the
Employer table (EmployerID)
is the common field that
relates this table to the
Position table.

PositionID is the primary key in


the Position table. The
EmployerID field is a foreign key
in this table.

Primary keys can only have one


occurrence in a table. Foreign keys
may have multiple occurrences.
ACCESS IS A RELATIONAL
DATABASE
• Access allows you to form relationships between the
tables; that’s why it’s called a relational database
• The simplest way to create a relationship
• Look for identical field names between tables.

• Tables can be joined in three ways; one-to-one,


one-to-many, and many-to-many.
CARDINALITY RATIOS ONE-TO-ONE

47
Cardinality Ratios One-to-Many

48
Cardinality Ratios Many-to-One

49
AN EXAMPLE OF A
ONE-TO-MANY
RELATIONSHIP
The Employer table is related to the Position table via the common field EmployerID.

The Employer table has


one record for EmployerID
value 10126. The Position
table has two records.
From Database tools choose Relationships

51
Choose tables you want to make relationship between
them.
52
53
54
• If you enforce referential integrity you cannot enter a value in the
foreign key field of a related table if that value doesn't exist in the
primary key field of the primary table .

• To delete a primary record and all related records in one operation


by selecting the cascade delete related records check box.

• To update a primary record and all related records in one


operation by selecting the cascade update related fields check box.

55
• 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.
• 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.

56
Task create these tables and add one-to-many
relationship between them.
WHAT IS AN ACCESS
QUERY?
• You can create a query when you need ONLY a portion of
the data form tables (or existing queries).
• For example, you may only need to see employees who live in
boston. The response would be to display only the records
whose state field matches with boston.
• Restrictions can be used
• Comparison operators
• The design view is used to specify the fields and records
you want to see.
CREATE QUERY
1) launch query design view
• Click query design from the create tab in the ribbon.

59
CREATE QUERY
2) select the tables
Select each table that
you need in the query
and click add to add it
to the query.

Once you've added all


the tables you need,
click close to close the
dialog box.

60
CREATE QUERY
3) add fields
We are now in design view.
The top pane is the diagram pane. It contains the
tables that we selected in the previous step. These
are the tables that are available for us to use in the
query.
The bottom pane is the query pane. It contains the
fields that we will actually use in the query, as well
as any filtering criteria that we specify.
Double-click a field from a table in the top pane to
make it appear in the bottom pane. Do this for
each field you'd like in the query.
By default, the show option is checked (in the
bottom pane). This indicates that the field will be
displayed when the query runs.

61
CREATE QUERY
5) run the query
Click !Run in the
ribbon to run the
query.

62
63
Sort and Filter group

FILTER
A set of criteria applied to data in order
to display a subset of the data or to sort
the data. In Access, you can use
filtering techniques, such as Filter By
Selection and Filter By Form, to filter
data.
For example: you can view the records of only those
people whose birthdays fall during a specific month by
clicking the appropriate menu commands
The filters that are available to you
depend on the type of data that is in
the selected column.

All Dates in Period filters ignore


the day and year portion of the date
values.
Icons in the column header and the
record navigator bar indicate that the
current view is filtered on the Birth
Date column.

Hovering the mouse over the


column heading displays a tip showing
the current filter criterion.

Outcome of a filter selection


Microsoft Office
Access SORTS
records in ascending
or descending order
without regard to
case.
Number, Currency, AutoNumber

Text, Memo, Hyperlink

Yes/No

Date/Time

You might also like