information systems and databases

47
Information Systems and Databases IPT HSC Topic 2

Upload: rosemary-rizk

Post on 22-Mar-2016

219 views

Category:

Documents


3 download

DESCRIPTION

Notes for the IS&DB topic

TRANSCRIPT

Page 1: Information systems and databases

Information Systems and

Databases

IPT HSC Topic 2

Page 2: Information systems and databases

Databases

Page 3: Information systems and databases

Database

★An electronic means to organise raw data

(facts)

★Transaction: an event that generates or

modifies data that is eventually stored in an

information system

Page 4: Information systems and databases

Organisation Methods

1. Database a. Flat file

b. Relational

2. Online

a. webpage contents laid out

Page 5: Information systems and databases

Flat File Databases

★One file system (one table) ○ eg. contacts, photo app

Page 6: Information systems and databases

Relational Database

★More than one file that are related ○ eg. shopping scenario

stock

customer

purchases

suppliers

orders

receiving

Page 7: Information systems and databases

Relational Database

Page 8: Information systems and databases

Database Design

Stock Purchases Owner Order Supplier Customer

- Item name

- Quantity

- Item name

- Quantity

- Date

- Time

- Total

- Payment method

- First name

- Last name

- DOB

- Street

- Phone number

- Suburb

- Post code

- City

- Email

- Business name

- Item name

- Quantity

- Company number

- Phone number

- Address

- Company name

- Phone no.

- Email

- Address

- First name

- Last name

- Phone no.

- Street no

- Street name

- Suburb name

- Post code

- City

- Email

Page 9: Information systems and databases

Schema/Entity-Relationship Diagram

Product

barcode

description

cost

price

image

perishable

Purchase

customer ID

barcode

date

time

total owning

quantity

payment method

Customer

customer ID

f name

s name

email

mobile

sex

address

entity

transaction entity

Page 10: Information systems and databases

Schema/Entity-Relationship Diagram

Supplier

supplier ID

name

contact f name

contact s name

address/suburb

phone number

email

address

Delivery

supplier ID

barcode

store ID

date

time

store

quantity

Product

barcode

description

price

cost

image

perishable

entity transaction entity

Page 11: Information systems and databases

Schema/Entity-Relationship Diagram

Store

store ID

business name

address/suburb

postcode

contact f name

contact s name

phone number

Order

order ID

barcode

supplier ID

store ID

date

time

quantity

Product

barcode

description

cost

price

image

perishable

entity transaction entity

Supplier

supplier ID

name

contact f name

contact s name

address/suburb

postcode

phone number

email address entity

Page 12: Information systems and databases

Example 1: School Timetable System

Student

student ID

student f name

student s name

year

dob

student timetable

Timetable

student ID

query results

teacher ID

teacher location

School Admin System

query results

teacher name

teacher location

student ID

student details

entity transaction entity

Admin Staff

teacher name

teacher location

entity

Page 13: Information systems and databases

Example 2: Video Store

Member

membership number

member f name

member s name

dob

Borrowing

membership number

movie barcode

date borrowed

time borrowed

return date

EFT card details

PIN

Bank

PIN

EFT card details

transaction

entity transaction entity

Page 14: Information systems and databases

Example 3: RTA

Customer

customer f name

customer s name

address/suburb

photograph

Borrowing

membership number

movie barcode

date borrowed

time borrowed

return date

EFT card details

PIN

Bank

PIN

EFT card details

transaction

entity

transaction entity

Page 15: Information systems and databases

Schema for Purchasing a Product

Product

barcode

.

.

.

Purchase

customer ID

barcode

date

time

payment type

Customer

customer ID

.

.

.

.

entity transaction entity

PK

PK

PK

PK

Page 16: Information systems and databases

Keys

★enable designer to link tables together in a

relational database

○ primary

○ foreign

○ composite

Page 17: Information systems and databases

Keys: Primary

★Unique code that identifies each instance of

that entity and/or transaction

○ eg. barcode is the primary key for the product’s table

★ Instance: one set of data recorded for the

entity or transaction

Page 18: Information systems and databases

Keys: Foreign

★Code that acts as a link to a primary key in

another table

○ eg. barcode in purchases table

★ It can have duplicates

Page 19: Information systems and databases

Keys: Composite

★Primary key that is made up of more than

one field/data item

★One field alone cannot be unique ○ eg. a customer can make a purchase of the same product

several times in a day therefore a primary key for the

purchases table must include the following data items:

customer ID, barcode, date of purchase and time of purchase

Page 20: Information systems and databases

Relationships

★one-to-one (1-1)

★one-to-many (1-∞)

★many-to-one (∞-1)

★many-to-many (∞-∞)

Page 21: Information systems and databases

Q21 HSC 2002

Location

room number

location

phone extension

Computer

computer number

computer RAM

computer hard disk

room number

entity entity

blue = primary key

red = foreign key

Page 22: Information systems and databases

Q21 HSC 2002 b) Identify the data redundancy in Mr. Ferrano’s database and outline the

problems it may cause as the database increases in size. Redundancy is the unnecessary repetition of data within a database. For Mr. Ferrano’s database,

the room number and phone extension are unnecessarily duplicated. As the database increases

in size, the redundant data will take up space in the database and cause longer processing time

thus slowing down the database. If changes were made to the room number or phone extension

then each record containing either the room number or phone extension will need to be edited

individually otherwise inconsistencies will occur.

Page 23: Information systems and databases

Q23 HSC 2012 a) Describe TWO problems that could arise from using this flat-file structure

as a database and propose a solution for each.

When an item is searched, not only will the item details be displayed but also the borrower’s details

will be shown. In order to correct this problem, separating the borrower details from the item detail

will rectify the problem. Another problem is that there are two fields relating Item and Borrower

and the borrower’s full name will be displayed in one field. Normalising the database will correct

this problem as it will separate the borrower’s full name into first name and surname.

Page 24: Information systems and databases

Q23 HSC 2012 c) A new library has all of its books, periodicals and audio-visual materials

stored in a large automated storage area located under the building.

Recommend and justify the most appropriate way to store each item to

allow for ease of retrieval.

The most appropriate way to store each item for easy retrieval is to organise the item by their item

number. The item number should correspond with details about the item such as item’s location in

the storage area or item size. Also using the ‘number of time borrowed’ field to place the items in

locations that will allow for faster retrieval i.e closer to the retrieval area.

Page 25: Information systems and databases

Stages of Normalising

★ 1st Normal Form: ○ separate field with more than one piece of information

★ 2nd Normal Form: ○ remove redundancies by designing a relational schema

★ 3rd Normal Form: ○ add primary and foreign key

★Domain key normal form: ○ add relationship

Page 26: Information systems and databases

Q23 HSC 2012

Loan

item number

date borrowed

date returned

borrower ID

number of times

borrowed

Item

item number

item

type

entity transaction

Borrower

borrower ID

borrower f name

borrower s name

entity

PK

FK

FK PK PK

Page 27: Information systems and databases

Labelling a Database

field

name

data record/tuple

type: text

length: 30

type: text

length: 6

type: text

length: 25 type: text

length: 15

type:

date/time

length: 6

type:

date/time

length: 6

type:

number

length: 2

Page 28: Information systems and databases

Defining Fields

1. name

2. datatype: text, data/time, number, object,

boolean (yes/no)

3. length

Page 29: Information systems and databases

Data Dictionary

Field Data type Length Description

Student ID Text 8 Student’s ID

Student first name Text 30 First name of student

Student last name Text 30 Last name of student

Female Boolean 1 If student is female

Year Number 4 Year student is enrolled in

DOB Date/time 6 Student’s date of birth

Family ID Text 8 Family ID of student

Eg. Student: Data Dictionary

A model that defines each data element that will be stored in the database. It is presented in tabular

form and specifies the name of the data element (field), its data type, length and a description of the

type of data that will be entered into that field.

Page 30: Information systems and databases

Calculate the size of a database

★500 loans

○ 1. size: calculate the size of 1 record

30 + 6 + 25 + 15 + 6 + 6 + 2

= 90

○ 2. multiply size of 1 record by number of records

90 x 500

= 45 000 bytes/1024

= approx 45 bytes

Page 31: Information systems and databases

Important note!

Foreign and primary keys that link

together in a relationship MUST

be defined in the SAME way:

both the data type and length are

the same

Page 32: Information systems and databases

Loan

item number

date borrowed

date returned

borrower ID

number of times

borrowed

Vehicle

Rego ID

Description

Cylinder

Capacity

Year

CTP Insurer

Owner

Owner ID

borrower f name

borrower s name

Page 33: Information systems and databases

Querying Databases

★Data Independence: where data in

database is stored separately from the

system managing the data (DBMS)!!!

Page 34: Information systems and databases

Querying Databases

★Query: a question to the database ○ eg.

1. Which customers live in the St. George area?

2. Which customers in the St George area make

purchases over >$100?

Page 35: Information systems and databases

Querying Databases

★A query is construct that draws out relevant

information from a database. It comprises of

4 key words (syntax)

Page 36: Information systems and databases

SQL - Structured Query Language

SELECT: lists the fields to extract from the

database

FROM: lists the table names

WHERE: specify the criteria

ORDER BY: sort the list

Page 37: Information systems and databases

Structured Query Language

1. Which customers live in the St. George area?

SELECT customer.Firstname,

customer.Surname

FROM CUSTOMER

WHERE customer.suburb=“Hurstville”

ORDER BY customer.surname ASC DSC

Page 38: Information systems and databases

Structured Query Language

2. Which customers in the St George area make

purchases over >$100?

SELECT customer.firstname, customer.surname,

SUM(purchases.price)

FROM PURCHASES, CUSTOMER

WHERE customers.suburb=“Hurstville” AND

SUM(purchase.price)>100

ORDER BY SUM(purchases.price)DESC,

customer.surname

Page 39: Information systems and databases

Set 2G - Question 12

a) Return all customers who live in NSW sorted on their last name

SELECT Customers.FirstName,

Customers.LastName

FROM Customers

WHERE customer.Town= “Frogtown”

ORDER BY customer.surname DSC

Page 40: Information systems and databases

Set 2G - Question 12

b) Return the number of different products for each unique order number

SELECT Products.ProductID, InvoiceProducts.Units

FROM Products, InvoiceProducts

WHERE Products.ProductID= “ ”

SUM(InvoiceProducts.Units, Products.ProductID)

ORDER BY Products.ProductID DSC

Page 41: Information systems and databases

SQL - WHERE

★LIKE

★BEGINS WITH

★CONTAINS

Page 42: Information systems and databases

Wildcards ★* - any characters, any number of characters

○ surname=“P*” - a surname beginning with P with any

number of characters following.

★? - any character, only 1 character ○ surname=“Riz??” - surnames beginning with Riz and

ending in 1 or 2 more characters.

○ postcode BEGINS WITH “20”

= “20??” - postcode beginning with 20 and ending in

2 more characters (digits)

Page 43: Information systems and databases

Comparative / Logic Operators in SQL

Comparative Operators

> greater than

< less than

= equal or identical to

>= greater or and equal to

<= less than or equal to

eg. price >=100

Logic Operators

AND

NOT

OR

Page 44: Information systems and databases

SQL Example: All clients living in St George

SELECT client.surname, client.firstname,

client.street, client.suburb, client.postcode

FROM client

WHERE client.postcode=“22??” AND

client.age>=18 AND client.age<=30

ORDER BY client.surname

Page 45: Information systems and databases

Data Independence

Page 46: Information systems and databases

Views of a Database ★ Different roles in an organisation use the

database in different ways that suit their

responsibilities

○ eg. secretary

■ data entry of resources/products,

clients

■ modification of data to reflect change

of details

○ manager

■ salary details of employees

■ same access as secretary

Page 47: Information systems and databases

Authentication Procedures

★ Authentication procedures determine the exact user and

their related access levels to the system

○ People with less access have Read + Execute

access.

○ People with slightly higher levels are able to Edit,

Add new, Read + Execute

○ People with maximum levels can Delete, Edit, Add

new, Read + Execute