Anda di halaman 1dari 46

MS21C Computer Applications

Productivity Tools Overview


Part 2: Databases
Overview
What is a Database?
Purpose of a Database
Foundation of a Database
Data and Information
How Data is Organized
Database Design - ER Diagram, Normalization,
Data Structure
Database Management System
Operations and Capabilities of a DBMS
Key Database Activities
Create a DB Table, DB Window, Design and
Data Sheet Views
Additional Resources
Database Skills
1. What is a Database?
A database is collection of related
tables/files. For example Event and Ticket
tables are in a EVENT_SALES database
whereas Order, Supplier, and Part are in an
ORDER_PROCESSING database.
A database is an organized collection of
related data that is shared by groups of
users.
2. Purpose of a Database
The purpose of a database is to help people
keep track of things a.k.a. entities and
provide information for decision-making.
What are entities?
Entities may be people, places and things e.g.
customers, schools, and books, respectively.
Entities may also be concepts or events that are
intangible but are stored nevertheless e.g. an
account or a transaction.
3. Foundation of a Database
Data is the foundation of a database.
The effectiveness of a database depends
on how data are stored.
Data and information are sometimes used
interchangeably.
This is erroneous!
4. Data and Information
Data raw, unformatted information
E.g.: 101574690
Information data that is transformed to
have a meaning
E.g.: 101-574-690; TRN
Data are the building blocks of information.
Information is derived by processing data.
Processing can be summarizing, listing,
converting (e.g. from numbers to a graph),
categorizing, calculating, etc.
5. How Data is Organized
Data are organized and referenced in
different units.
Units range in size from a bit (binary digit)
to a database.
A bit or binary digit is the smallest unit of
data which represents a 0 or 1.
A byte is a group of eight bits representing
a single character, which can be a number,
letter, or symbol.
5. How Data is Organized
A field is a group of related characters
that represent a basic fact or value, or
describe an entity. Name, age, gender,
salary are examples of fields. Fields are
a.k.a. attributes.
A record is a group of related fields that
represent an entity. For example, a
TICKET record may have the fields:
ticket_number, ticket_date, event, and
seat_number. Records are also referred to
as tuples.
5. How Data is Organized
Bit 0 or 1

Byte 01000011 (Letter C in ASCII)

Field August 21, 2007 (DATE Field)

TicketNum TicketDesc SeatNum EventNum


Record 19 Day Pass A12 10

TicketNum TicketDesc SeatNum EventNum


19 Day Pass A12 10
45 Season Pass B14 20
File
17 Day Pass A10 25

Event Sales Database


Event Table Ticket Table
Database
Sale Table
5. How Data is Organized
A file is a collection of records of the same
type. For example ticket records are stored
in the TICKET table and event records are
stored in the EVENT table. Tables are a.k.a.
entities.
Recall, a database is a collection of related
tables/files. For example Student, Course,
and Instructor tables are in a
REGISTRATION database whereas Sales,
Cash, Account_Receivable, and
Accounts_Payable are in an ACCOUNTING
database.
6. Database Design
The best database in the world is no better
than the data it holds!
Conversely, all the data in the world will do
you no good if they are not organized in a
manner in which there are few
redundancies and in which you can retrieve,
analyze and understand them.
Therefore, both the data in- and the
structure of- the database are key
elements in database design.
6-1. Database Design, ER Diagram
When designing a database a diagramming technique
called Entity Relationship (ER) Diagram is sometimes
used.
In your course you will not be using this technique but
database designers often do.
ER diagrams allow database designers to talk with
people throughout the organization to make sure that
all entities and relationships have been found.
To create an ER Diagram, you draw entities as boxes
and draw lines between entities to show relationships.
A line connecting two entities that ends in two short
marks designates a one-to-one relationship.
A line connecting two entities that ends in with a crows
foot topped by a short mark indicates a one-to-many
relationship.
6-1. Database Design, ER Diagram
Has
Team Players

Participates Has

Has Game
Games
Statistics

The example above shows an ER diagram for the global Cricket


fraternity. From the diagram you see the following associations:
Each Team has Players
Each Team participates in Games
For each Player and Games there are Game Statistics
6-2. Database Design - Normalization
To be effective, databases must be efficient.
Normalization is a technique to make
complex databases more efficient and is
achieved through the elimination of
redundant data.
In your course you will not be using this
technique but it is important to understand its
relevance.
Lets say we want to create a database for
students. Students personal, course and
instructor information, ID number and course
grades are to be stored in the database.
6-2. Database Design - Normalization
Database of students, courses, instructors and grades with redundant data.

This redundancy means that the database is not well organized.


If, for example, you want to change the phone number of an
instructor who has hundreds of students, you have to change
this number hundreds of times.
6-2. Database Design, Normalization
Organization of information on students, course, instructors and grades
after normalization.
6-3. Database Design Data Structure
Data are stored in tables, where each table has rows and
columns, similar to a spreadsheet.
Rows represent tuples (records) and columns represent
attributes (fields).
To distinguish between records in an entity correctly each
record MUST have a unique identifier primary key.
The properties of a primary key are:
Not null/empty (i.e. a ticket cannot have a blank
Ticket Number).
Unique each ticket has a unique identifier
Ticket_Number.
Each entity (table) MUST have a primary key in order to
store and retrieve data accurately.
6-3. Database Design, Data Structure
A primary key can either be a single attribute
or a combination of two or more attributes.
When a primary key is a combination of
attributes, it is called a composite key.
A database usually has multiple tables, with
each table storing data about a different
entity.
To retrieve data/information from a database
it is necessary to relate data from separate
tables, i.e., establish relationship between
the tables.
6-3. Database Design, Data Structure
Data from separate tables are related by
placing the primary key from one table in
another related table and this attribute is
referred to as a foreign key.
A foreign key refers to an attribute that
appears as a non-primary key attribute in one
entity and as a primary key attribute (or part
of a primary key) in another entity.
6-3. Database Design, Data Structure
Referential Integrity refers to the
consistency between related tables.
Referential integrity is usually enforced by
the combination of a primary key and a
foreign key. For referential integrity to hold,
any field in a table that is declared a foreign
key can contain only values from a parent
table's primary key. For example, EventNum
in the TICKET table must have matching
values in the EVENT table. Otherwise the
database will be inconsistent or unsound or
lack integrity.
6-3. Database Design Data Structure
Recall, data are stored in tables, each having
rows and columns, similar to a spreadsheet.
Recall, rows represent records and columns
represent fields.
A database usually has multiple tables, with
each table storing data about a different
entity.
For example, an EVENT table has data about
events and a TICKET table has data about
tickets. These tables are all a part of an
EVENT SALE database.
6-3. Database Design Data Structure
Columns (Attributes, Fields)
Are these two tables
Table related?
(Relation)

TicketNum TicketDesc SeatNum EventNum


19 Day Pass A12 10
45 Season Pass B14 20
TICKET Rows
17 Day Pass A10 25 (Records,
Tuples)
23 Day Pass C22 10
13 Day Pass B67 25

EventNum EventType EventDate


10 One Day International 17/08/07 ???
EVENT
20 One Day and Test 17/08/07
25 Three-day Test 28/08/07

???
6-3. Database Design Data Structure
Each attribute in a database needs to be of a
certain data type.
Data types indicate the type of data that a field
or column can hold.
In MS Access, data types include text, number,
date/time, currency and hyperlink.
Data types impose consistency on the data
values in a column or field.
Some data types come with built-in restrictions
and validation. For example, if the field DOB has
the date/time data type, the database system
will automatically check that all DOB data are
valid dates.
7. Database Management System
Now that you have identified the entities and
data required for a database, you will need a
Database Management System (DBMS) to
help you manage and use the data.
A DBMS is a specific type of software for
creating, storing, organizing and accessing
data from a database.
MS Access is a DBMS for desktop systems
and youll be using this application in your
course.
8. Operations of a DBMS
Suppose we wanted to find out which event
did ticket holders 23 or 45 attend?
We would need information from two tables:
TICKET and EVENT.
To obtain useful sets of data, such as the
information required to answer the question
above, the DBMS uses three basic
operations: select, join and project.
8. Operations of a DBMS
Select:
The select operation creates a subset consisting of all
records (rows) in the table that meet stated criteria.
In our example we want to select records from the
TICKET table where the TicketNum equals 23 or 45.
Join:
The join operation combines tables to provide you with
more information than is available in individual tables.
In our example we want to join the now-shortened
TICKET table (only tickets 23 or 45 will be presented)
and the EVENT table into a single new table.
8. Operations of a DBMS
Join Types:
Inner Join (default) on the basis of the data in the joined
fields, rows from one of the joined tables correspond to rows in
the other table.
Use an inner join if you want to return only those records from both
tables in the join that match on the joining field.
Left Outer Join left outer joins include all of the records from
the first (left) of two tables, even if there are no matching values
for records in the second (right) table.
For example, you could use LEFT JOIN with the Departments (left)
and Employees (right) tables to select all departments, including those
that have no employees assigned to them.
Right Outer Join right outer joins include all of the records
from the second (right) of two tables, even if there are no
matching values for records in the first (left) table.
For example, you could use RIGHT JOIN with the Departments (left)
and Employees (right) tables to select all employees, including those
that are not assigned to a department.
8. Operations of a DBMS
Project
The project operation creates a subset consisting
of columns in a table, permitting you to create
new tables that contain only information required.
In our example we want to extract from the new
table only the following columns: TicketNum,
TicketDesc, EventType and EventDate.
8. Operations of a DBMS
TICKET

TicketNum TicketDesc SeatNum EventNum EVENT


19 Day Pass A12 10
EventNum EventType EventDate
45 Season Pass B14 20 10 One Day 17/08/07
17 Day Pass A10 25 International

23 Day Pass C22 10 20 One Day and Test 17/08/07

13 Day Pass B67 25 25 Three-day Test 28/08/07

Select TicketNum = 23 or 45 Join by EventNum

TicketNum TicketDesc EventType EventDate


45 Season Pass One Day and Test 17/08/07
23 Day Pass One Day International 17/08/07

Project: TicketNum, TicketDesc, EventType and EventDate

The three basic operation of a DBMS:


The select, join (inner) and project operations enable data from two or more different
tables to be combined and only selected attributes to be displayed.
9. Capabilities of a DBMS
A DBMS have a data definition capability
that enables you to specify the structure of
the content of the database.
The data definition capability is used to
create database tables and to define the
characteristics of the fields in each table.
This information about the database would be
documented in a data dictionary.
Data in the data dictionary is referred to as
Metadata.
9. Capabilities of a DBMS
Metadata:
Often described as data about data
Provides a description of the characteristics of the data
and how it is used in a database.
Includes data type as well as other descriptors or
characteristics.
For example the field, TicketDesc is text (data type)
and is 15 characters in length (size).
Other metadata can include format (e.g. for a date field,
is it mm/dd/yy or yyyy/mm/dd), and default value (e.g.
your Pipeline default password is your DOB).
Metadata makes databases more useful and
understandable.
9. Capabilities of a DBMS
Data Dictionary:
MS Access has a
built-in rudimentary
data dictionary
capability that
displays information
about the name,
description, size, type
and format of each
field in a table when it
is in Design View.

Note: The small key icon to


the left of TicketNum indicates
that it is the primary key field.
10. Key Database Activities
Entering data in the database:
Forms can be used to enter data into the
database.
Forms typically has blanks where the user can
enter information. Each blank represents an
attribute within a table.
Forms presents information to the user in an
intuitive way so that the user can easily see and
enter the data
Forms can be used to add, modify and delete
data from the database.
10. Key Database Activities
Retrieving data from the database:
To retrieve information from a database you use a
query.
MS Access allows you to query the database
using a concept called query by example (QBE).
QBE capabilities in Access enable you to fill out a
grid, or a template in order to construct a sample
or description of the data you would like to see.
10. Key Database Activities
This is an example of
the QBE grid in MS
Access.
The query in the
example retrieve tickets
assigned seat numbers
starting with A.
Note: the * is a
wildcard and can be
used to represent any
character.
Note: As you do in
Excel you can use
comparison operators
in MS Access queries.
You can use the Like
operator to find values
in a field that match the
pattern you specify.
10. Key Database Activities
Report generation:
A report is a compilation of data from the database
that is organized and produced in printed format.
Reports are typically produced on paper but they can
be presented to users on-screen as well.
Reports have different sections:
Report Header this section is printed just once, at the
beginning of the report. Use the report header for
information that might normally appear on a cover page,
such as a logo, a title, or a date. When you place a
calculated control that uses the Sum aggregate function in
the report header, the sum calculated is for the entire report.
The report header is printed before the page header.
10. Key Database Activities
Reports have different sections contd:
Page Header this section is printed at the top of every page.
For example, use a page header to repeat the report title on every
page.
Group Header this section is printed at the beginning of each
new group of records. Use the group header to print the group
name. For example, in a report that is grouped by product, use the
group header to print the product name. When you place a
calculated control that uses the Sum aggregate function in the
group header, the sum is for the current group.
Detail this section is printed once for every row in the record
source. This is where you place the controls that make up the
main body of the report.
Group Footer this section is printed at the end of each group
of records. Use a group footer to print summary information for a
group.
Report Footer this section is printed just once, at the end of
the report. Use the report footer to print report totals or other
summary information for the entire report.
11. Create a DB MS Access
Step 1: Start Access
Step 2:Click 'Blank Database'
11. Create a DB MS Access
Step 3 - As soon as
you click the Blank
Database button, the
right side of your
Access screen will
change and look like
the image on the right Database
Name
Choose a location Location
(Desktop) and name
for your DB
Click the Create button
and youre done
Create Button
11. DB Window MS Access
Tabs

Ribbon

Group
s

Table
Object
Name
s

Well
focus on
these
objects
in the
course
12. Create Table MS Access
On the left of the Table Tools-Datasheet
Tab/Ribbon youll see a View button. Click
the View button.
When you click the View button the
image on the left will appear. Since we
want to create or design a new Table,
well click the Design View selection.

A Save As menu screen will appear


similar to the image on the right.
Type Ticket in the Table Name: area
and then click the OK button.
13. Design View (Table) MS Access
13. Design View (Table) MS Access
Design View allows you to create the fields for each
entity so that data can be entered into the database.

Click
Datasheet
View
13. Data Sheet View (Table) MS Access
The data sheet allows you to enter data into the DB

next
first record record new
last
previous record record record
14. Additional Resources
For a better understanding of the major
database activities to be covered in this
module of the course, students are required
to complete the DB tutorial.
15. Database Skills
Creating and relating tables
Enforcing referential integrity
Entering and modifying data
Creating forms
Creating queries: single/multi table,
stored/calculated fields
Creating reports: with/without summaries
(aggregates)

Anda mungkin juga menyukai