INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

48
INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI

Transcript of INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

Page 1: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

INTRO TO DATABASESPart I

IS 340

BY

CHANDRA S. AMARAVADI

Page 2: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

2

IN THIS PRESENTATION..

Entity classes, entities, attributes Database organization

file, record, attribute/field DBMS activities and functions DBMS components Importance of databases

Page 3: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

NEED FOR DATABASES

A church needs to maintain information on A church needs to maintain information on donationsdonations A consulting company needs to manage its contactsA consulting company needs to manage its contacts A doctor needs to know if a patient is allergic to a A doctor needs to know if a patient is allergic to a particular medication.particular medication. An airline exec needs to know occupancy on a An airline exec needs to know occupancy on a flight.flight.

Page 4: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

4

BASIC DATA CONCEPTS

Page 5: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

5

THERE ARE THINGS ANDOBJECTS IN THE REAL WORLD

These are called entities.

Page 6: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

WE ARE MORE INTERESTED IN

Organization

Eclasses

Produce customers

Sales/vendorsmachines/parts

Page 7: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

7

ENTITY CLASSES HAVE PROPERTIES

Properties are calledattributes

Produce customers

Sales/vendorsmachines/parts

Barcode#, price per unit, supplier, total qty

Page 8: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

8

DISCUSSION

Classify the following as entity, entity class or attribute

John San Francisco (as a city) Customer Book Store# Nintendo DS Microsoft Microsoft employees The book “Great Expectations” Invoice Production

Page 9: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

9

BASIC ORGANIZATION CONCEPTS

Page 10: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

10

DATA VS INFORMATION

Data about an entity are raw facts. Are they useful?

December 30th, 1984Played for Cavs and Heat

Born March 28th , 198615m albums sold

Car driven by Bobby Redhall

Page 11: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

11

INFORMATION IS USEFUL IF COMPLETE

Example information about a person

Name: Chris NashDOB: 2-4-1965 Profession: EngineerAddress: 415 Walnut street.

This describes a personmore. It is called ????.

Page 12: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

12

ANOTHER EXAMPLE

Example information about a credit card transaction:

Acct#: 4555950Date: 12/5/08Time: 4:48 pmMerchant: WIU UnionCard type: Master CardIssuer: First Bank

This describes a transactionmore.

Page 13: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

13

ONE ATTRIBUTE HAS A UNIQUE VALUE

Which of these has a unique value?

Acct#: 4555950Date: 12/5/08Time: 4:48 pmMerchant: WIU UnionCard type: Master CardIssuer: First Bank

The unique attribute iscalled ???

3300 3305 3313

Page 14: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

14

ORGANIZATION OF DATA/INFORMATION

Transaction#: 55643Date: 12/5/10Time: 4:08 pmMerchant: VitalesCard type: Master CardIssuer: First Bank

Transaction#: 55644Date: 12/6/10Time: 4:10 pmMerchant: WIU UnionCard type: Master CardIssuer: First Bank

Observations about these two “units” of data?

Page 15: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

15

TRADITIONAL CONCEPT OF A FILE

CBT QUALITY MANAGEMENT COMMITTEEMeeting Minutes

Meeting Date/time: December 2nd, 2:00 p.m.Present: Larry Wall, Ken Nimrick, Xiang Yi,

Western Illinois University strives to maintain a community which values academic excellence; institutional integrity; and justice, equity, and diversity. Such an environment is essential in fostering the intellectual growth and personal development of all students. Each member of the University community shares responsibility in maintaining conditions which support the University's purpose. The Code of Student Conduct is designed to provide basic guidelines to advance the University's mission as a premier educational institution.

Page 16: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

16

Transaction

ID

Transaction

Date

Transaction

Time

Merchant

55643 12/05/09 4:08 pm Vitales

55644 12/05/09 4:10 pm WIU Union

CONCEPT OF A DATABASE FILE

Page 17: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

17

DEFINITIONS

Page 18: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

18

Primary key

Record

attr. values

Attributes/field namesStructure/schema

DATABASE ORGANIZATION

PROD# DESCR. PRICE QUANTITY

IR888E Refrigerator $1,800 20

TS3233 Television $67 32

Record

Page 19: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

19

Database – A group of related filesFile/table – A group of related recordsRecord – a grouping of related field valuesAttribute – property e.g. hair color

Schema -- This is the logical view of the database (tables and fields)Primary key – An attribute whose values are unique within a fileSecondary key – Any other attributeDBMS – software program to provide controlled data access

Database

Files/tables

Records

Attr. values

DATABASE ORGANIZATION

Page 20: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

20

DATA MODELS AND

DBMS MODELS

Page 21: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

21

Organization

Entity classes

Data model

File 2

File 1

Data base

cust.cust.

emp.emp.

Page 22: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

22

DATA MODELS

Abstract view of the data & relationships

Captures data needs

Supports implementation

Relationship between students and courses?

between doctors and patients?

between teams and players?

Page 23: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

23

DEFINITIONSEntity – Individual example of person, place or thing.Entity Class – Collection of related entities.Attributes – Properties of entity classes about which we would like to collect information.

Page 24: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

24

DATA MODELS…

Three types of relationships among entity classes

A B1:1

A B1:M

A BM:N

For each value of A, oneand only one value of Band vice versa.

For each value of A, many values of B, but for each B only one A.

For each value of A, many values of B and vice versa.

Page 25: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

25

DISCUSSION

Identify the types of the following relationships

Company -- president Instructor -- students Flights -- pilots City -- convention centers Club -- members Team -- players Company -- city Books – authors Artists -- records

Page 26: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

26

DBMS ACTIVITIES

Page 27: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

27

DBMS ACTIVITIES & FUNCTIONS

Activities with DBMS

Define structure/schema

Enter data

modify data

query data

get reports

Page 28: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

28

Define structure/schema

DBMS ACTIVITIES & FUNCTIONS

Field Name Data type Description Length Decimals

Prod# Numeric Unique prod code

6 0

Descr Text Short prod

description

25 0

Price Currency Product price 6 2

This is called data definition

Page 29: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

29

Enter data -- Create a data entry form

PRODUCT DATA ENTRY

Product #:

Description:

LabelField

Heading

Data entry form

DBMS ACTIVITIES & FUNCTIONS

Page 30: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

30

DBMS ACTIVITIES & FUNCTIONS

AddDeleteChange

Modify data

Records/field values

Page 31: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

31

DBMS ACTIVITIES..Database Retrieval

Page 32: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

32

Query data – can use QBE or SQLlist products costing more than $2,000

Query by example (QBE) form

DBMS ACTIVITIES & FUNCTIONS

Prod# Descr. Price Quantity

> 2,000

Page 33: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

33

DATABASE RETRIEVAL

THE STRUCTURED QUERY LANGUAGE

Each SELECT statement has three parts SELECT, FROM and WHERE

SELECT is used to select output attributes FROM is used to specify the tables WHERE is used for row selection criteria

SELECT <attr. list>FROM <tables>WHERE <condition1, condition 2…>

Page 34: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

34

Flt# Pname Confirm#

AA1802 Smith PA5R2

PA802 Smith LX5R2

UA3702 Mahoney ZB46A

Select Flt#, Confirm#From ReservationWhere Pname = “Smith”;

Reservation

DATABASE RETRIEVAL..

SQL QUERY RESULTFlt# Confirm#AA1802 PA5R2PA802 LX5R2

Page 35: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

35

SELECT Flt#, Deptime, ArrtimeFROM ??WHERE Depcity = "PHX" and Destcity = "ORD";

Flt # Depcity Destcity Deptime Arrtime

AA 802 PHX ORD 1:51 AM 6:05AM

UA 3702 COS D 7:35 AM 8:05 AM

AA 812 PHX SEA 4:55 AM 9:00 AM

D 42 PHX ORD 5:40 PM 9:15PM

FLIGHTS

ANOTHER EXAMPLE

What is the result of the query?

Page 36: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

36

DISCUSSION

Write SQL queries to list:1) employee names.2) Employees who live in Macomb.3) employees who enjoy soccer.

EID E_name E_addr. E_city

423 Smith 100 Oak lane Macomb

425 Smith 100 Oak lane Macomb

501 Johnson 1430 N. Park street Rock Island

EMP.

Page 37: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

37

THE THEORY OF RETRIEVAL

DEPTS.

EMPLOYEES

have

EID E_name E_addr.

11893 Jon 100 Oak street

11895 Carey 15 Candy lane

11896 Ross 1317 Fox creek

D_code D_name D_mgr

Fin. Finance Jon

Sas Sales and service Ross

Acc. Accounts Jan

Emp. file

Dept. file

Page 38: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

38

SELECT table1.attr1, table2.attr2 . . . .

FROM table1, table2, . . . . .

WHERE table1.fkey = table2.fkey AND/OR

condition1 AND/OR

. . . . . . . . . . . . . ;

MULTI-TABLE SELECT STATEMENT

NOTE When there are multiple tables, attr. names preceded by table name The values of common attr. need to be equal in the WHERE part There can be more than one condition, connected by AND or OR

Page 39: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

39

RH

PH

Detail

FieldsPF

RF

PRODUCT LISTING

PRODUCT # DESCR. PRICE

Product # Descr. Price

Average Price

Title

Column

Headings

Footer

A report specification

Page 40: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

40

GETTING DATA OUT..

PRODUCT LISTING

PROD# DESCRIPTION PRICE

M100 Chair $ 50.00 M150 Table $200.00

Average Price $153.00

A generated report

Page 41: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

41

Define structure /schema Enter data modify data query data get reports

Activities with DBMS

Page 42: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

42

DBMS ORGANIZATION

Page 43: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

D B M S Kernel

D B M S Kernel

Major Components of DBMS

Export/Import

Data Defn.Data Defn. SQLSQL

Prog. Language Interface

Prog. Language Interface

DataDiction-

ary

DataDiction-

ary

Screen/ReportGen.

Screen/ReportGen.

Appln.Gen.

Appln.Gen.

43

Page 44: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

DBMS COMPONENTS..Data definition – the facility through which schema is defined. (how new tables are created).SQL interface – the facility through which SQL commands are typed in.Programming language interface – the facility which processes SQL commands embedded in application program. Also known

as the host language interface. Data dictionary – the facility that records details about the schema, reports, data entry forms etc.Screen & reports- the facility through which data entry screens and reports are created.Appln. Generation- the facility through which applications are created.Export/Import -- the facility through which files can be imported/exported in different DBMS formats.DBMS Kernel -- the actual programs which interact with the O/S and carry out data I/O.

44

Page 45: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

45

USEFULNESS OF DATABASES

Page 46: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

46

Suppose we have detailed information on each and every transaction in a store, what can we do with that?

What if a customer wants to return a shirt purchased in the store?

What if a manager wants to know what products were sold on a particular day?

USAGE OF DATA/INFORMATION

Page 47: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

47

To store and record information e.g. bal, price, grades etc. To retrieve information e.g. check#432 cashed? To report information e.g. daily sales To answer queries e.g. how many shoes were sold?

IMPORTANCE OF DBMS’s

Databases are used:

To analyze trends Identify sales prospects

Advanced uses:

Page 48: INTRO TO DATABASES Part I IS 340 BY CHANDRA S. AMARAVADI.

48

THAT’S ALL FOLKS!