Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer?...

25
Introduction to Databases CIS 5.2
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    213
  • download

    0

Transcript of Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer?...

Page 1: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Introduction to Databases

CIS 5.2

Page 2: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Where would you find info about yourself stored in a computer?

• College• Physician’s office• Library• Grocery Store• Dentist’s office• Verizon• IRS …

Page 3: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

General Definition

• A DATABASE is a collection of related data.

• Data = known facts that can be recorded and have implicit meaning.

Page 4: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

“Miniworld”

Each database can be viewed as representing a part of the real world, called a “miniworld.”

Page 5: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Size of a database

• Small database example: your personal phone directory

• Large database example: database of the IRS

Page 6: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

DBMS – Database Management System

A collection of programs that enables users to create and maintain a database.

Page 7: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

MS Access is a DBMS

In ACCESS, a DATABASE consists of a collection of tables.

Page 8: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Example of a DatabaseSTUDENT Table:

COURSE Table:

GRADE_REPORT Table: StudentNumber SectionIdentifier Grade 17 112 B 17 119 C 8 85 A 8 92 A 8 102 B 8 135 A

PREREQUISITE Table: CourseNumber PrerequisiteNumber CIS22 CIS15 MAT240 MAT140 CIS72 CIS71

Name StudentNumber Class Major Smith 17 1 CIS Brown 8 2 MATH

CourseName CourseNumber CreditHours Department Intro to Computer Science CIS1.1 3 CIS Data Structures CIS22 4 CIS Discrete Mathematics MAT240 3 MATH Databases CIS72 3 CIS

Page 9: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Table

• A table is defined by its columns, called fields.

• Each row (or entry) in a table is called a record. A record is the information about a specific person, product, or event.

Page 10: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Starting ACCESS

1. Begin ACCESS2. Open a blank Database –

although a database consists of many files, in Access, each database is viewed as a single file, hence a single icon.

Page 11: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Defining a TABLE

A TABLE is defined by its fields (column headings).

1. Field Name – unique name

2. Data Type – type of info a field can contain.

3. Description – comments about field.

Page 12: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

PRIMARY KEY

• Each table must have a primary key which is a unique unique identifieridentifier for each record.

• Eg. ID number for a student, course number for a course, driver number for a driver, etc.

Page 13: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Two VIEWS of a Table

1. Design View – view the table’s definition, I.e. the fields and their properties.

2. Datasheet View – view the actual records in the table.

Page 14: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Database Design

• Arranging data into tables and fields.

• This process can be long and difficult.

Page 15: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Remove Redundancy

WHY?• Wastes space • Updating is difficult

• Inconsistent data may result

Page 16: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Maintenance• Modifying the data

– Add records– Delete records– Update records

• Modifying the design– Add fields into tables– Remove fields from a table– Change characteristics of existing

fields

Page 17: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Query Types

• Select Query – chooses data from a table and displays it.

• Update Query – updates records in a table

• Delete Query – deletes records from a table.

Page 18: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Validation Rules

• Validation Rules are rules that a user must follow when entering data into a database.

• Validation Text – the message that appears if the user enters the wrong type of data.

Page 19: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Validation Rules

• Indicate that a field is required

• Entry must lie within a given range

• Specify a valid collection of values

• Specify a default value

• Change lowercase to UPPERCASE

Page 20: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Referential Integrity

• Primary Key - unique identifier for each record in a table.

• Foreign Key – a field in a table whose values must match a primary key in another table.

Page 21: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Referential Integrity

• We can define a relationship between two tables.

ONE – to – MANY Relationship

Primary key Foreign Key

Page 22: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Indexes

An INDEX in the back of a book contains important words or phrases (in alphabetical order) together with a list of pages on which the given word or phrase can be found.

Page 23: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Indexes

• An INDEX on a table in ACCESS is a list of names in alphabetical order and their locations in the table.

• The INDEX can be constructed on any field, not only on the names. The field on which the index is built is called the index key.

Page 24: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

Index

• An index is used instead of physically sorting the records.

• An index is automatically created for the primary key of every table.

Page 25: Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.

When should you create an INDEX?

• Frequent need of sorted data.• Frequent searches on that

field.

• Note: updates on an indexed field will be slower since the index must also be updated.