Database Systems

54
Database Systems Information Systems Intermediate 2

description

Database Systems. Information Systems Intermediate 2. Data and Information. Data is raw, unprocessed facts and figures. Data is collected, stored and processed by computers. Examples of Data 368 HR101FE 010468 Baker 25168. Data and Information. - PowerPoint PPT Presentation

Transcript of Database Systems

Page 1: Database Systems

Database Systems

Information SystemsIntermediate 2

Page 2: Database Systems

Data and Information Data is raw, unprocessed facts and

figures. Data is collected, stored and processed

by computers. Examples of Data

368 HR101FE 010468 Baker 25168

Page 3: Database Systems

Data and Information Information is processed data with

structure or meaning. Information is useful to humans. Examples of Information

Age: 36 years 8 months Post Code: HR10 1FE Date of Birth: 01/04/68 Occupation: Baker Total Spent: £251.68

Data 368 HR10 1FE 010468 Baker 251.68

Page 4: Database Systems

What is a database? A database is a collection of related

information about a set of persons or objects.

Traditionally, databases have been manual paper based systems.

Example: the “Yellow Pages”

Page 5: Database Systems

What is a database management system? A database management system

(DBMS) is a software package which is used to create, manipulate and present data from electronic databases.

Example of DBMSs include Microsoft Access and Filemaker Pro.

Page 6: Database Systems

Traditional databases storage of paper records was very bulky easy to miss-file a record, or records to be lost or

damaged data often duplicated in several records keeping records up-to-date was difficult and time

consuming, and often resulted in data inconsistency, where duplicated values were updated in one record but not in others

many people employed to maintain the records, which was costly

searching for records was time consuming producing reports, such as sorted lists or data

collated from several sources, was extremely time consuming, if not impossible

Page 7: Database Systems

Case Study: DVD Rentals

Member Number Title Forename Surname Telephone No.1012 Miss Isobel Ringer 2938471034 Mr John Silver 1425361056 Mr Fred Flintstone 8172631097 Mrs Annette Kirton 384756

Page 8: Database Systems

Case Study: DVD Rentals

DVD Code Title Cost Date Out Date Due Member Number Name002 Finding Nemo £2.50 03/09/04 04/09/04 1034 John Silver003 American Pie £2.50 27/08/04 28/08/04 1056 F Flintstone

01/09/04 02/09/04 Isobel Ringer008 The Pianist £2.50 04/09/04 06/09/04 1097 Annette Kirton011 Notting Hill £2.50 27/08/04 28/08/04 1012 I Ringer

04/09/04 06/09/04 1086 F Flintstone014 Prime Suspect £2.00 27/08/04 28/08/04 Annette Kirton015 Shrek £1.50 10/09/04 11/09/04 1034 Joan Silver

Page 9: Database Systems

Benefits of computerised databases Editing data is easy and therefore data

should be more accurate and up to date. Searching, sorting and calculating

operations can be performed much more quickly and easily.

Information is more easily available to users, due to improved methods of data retrieval.

Data integrity is improved resulting in more accurate information.

Page 10: Database Systems

Types of computerised database

Flat file Relational

Page 11: Database Systems

Flat file databases

DVD Code Title Cost Date Out Date Due

Member Number Name

Telephone Number

002 Finding Nemo £2.50 03/09/04 04/09/04 1034 John Silver 142536

003 American Pie £2.50 27/08/04 28/08/04 1056 Fred Flintstone 817263

003 American Pie £2.50 01/09/04 02/09/04 1012 Isobel Ringer 293847

008 The Pianist £2.50 04/09/04 06/09/04 1097 Annette Kirkton 384756

011 Notting Hill £2.50 27/08/04 28/08/04 1012 Isobel Ringer 293847

011 Notting Hill £2.50 04/09/04 06/09/04 1056 Fred Flintstone 817263

014 Prime Suspect £2.00 27/08/04 28/08/04 1097 Annette Kirkton 384756

015 Shrek £1.50 10/09/04 11/09/04 1034 Joan Silver 142536

Page 12: Database Systems

Limitations of flat file databases Data is very likely to be duplicated. The duplication of data leads to the

possibility of data inconsistency. It is not possible to store information

about a member without entering details of a DVD. This is called an insertion anomaly.

Removing a DVD from the database may remove the only record which stores details of a Member. This is called a deletion anomaly.

Page 13: Database Systems

Relational databases

A relational database stores data in more than one table.

The idea is to ensure that data is only entered and stored once, so removing the possibility of data duplication and inconsistency.

Page 14: Database Systems

Entities and Data Relationships An entity represents a person or object.

e.g. Member, DVD Rental Each entity has a set of attributes which

describe examples or instances of that entity. The attributes of the DVD Rental entity are

code, title, cost, date out, date due and member number

The attributes of the Member entity are member number, name and telephone number.

Page 15: Database Systems

Entities, Attributes and Instances

MEMBER

Member Number Member Name

Telephone Number

1012 Isobel Ringer 293847

1034 John Silver 142536

1056 Fred Flintstone 817263

1097 Annette Kirton 384756

Page 16: Database Systems

Entities, Attributes and Instances

The Member entity is the whole table

MEMBER

Member Number Member Name

Telephone Number

1012 Isobel Ringer 293847

1034 John Silver 142536

1056 Fred Flintstone 817263

1097 Annette Kirton 384756

Page 17: Database Systems

Entities, Attributes and Instances

The Member entity is the whole table

MEMBER

Member Number Member Name

Telephone Number

1012 Isobel Ringer 293847

1034 John Silver 142536

1056 Fred Flintstone 817263

1097 Annette Kirton 384756

Each column stores one attribute, e.g. Member Name

Page 18: Database Systems

Entities, Attributes and Instances

The Member entity is the whole table

MEMBER

Member Number Member Name

Telephone Number

1012 Isobel Ringer 293847

1034 John Silver 142536

1056 Fred Flintstone 817263

1097 Annette Kirton 384756

Each column stores one attribute, e.g. Member Name

Each row stores one instance, e.g. Member 1034

Page 19: Database Systems

Entities, Attributes and Instances An entity represents a person or object.

e.g. Member, DVD Rental Each entity has a set of attributes which

describe examples or instances of that entity. The attributes of the DVD Rental entity are

code, title, cost, date out, date due and member number

The attributes of the Member entity are member number, name and telephone number.

Page 20: Database Systems

Data Relationships

Three types of relationship: One-to-one One-to-many Many-to-many

Page 21: Database Systems

Data Relationships

One-to-one

VEHICLE

REGISTRATIONNUMBER

Page 22: Database Systems

Data Relationships

One-to-one

One-to-many

VEHICLE

REGISTRATIONNUMBER

MEMBER

DVD RENTAL

Page 23: Database Systems

Data Relationships

One-to-one

One-to-many

Many-to-many

VEHICLE

REGISTRATIONNUMBER

MEMBER

DVD RENTAL PUPIL

TEACHER

Page 24: Database Systems

Flat file databases

DVD Code Title Cost Date Out Date Due

Member Number Name

Telephone Number

002 Finding Nemo £2.50 03/09/04 04/09/04 1034 John Silver 142536

003 American Pie £2.50 27/08/04 28/08/04 1056 Fred Flintstone 817263

003 American Pie £2.50 01/09/04 02/09/04 1012 Isobel Ringer 293847

008 The Pianist £2.50 04/09/04 06/09/04 1097 Annette Kirkton 384756

011 Notting Hill £2.50 27/08/04 28/08/04 1012 Isobel Ringer 293847

011 Notting Hill £2.50 04/09/04 06/09/04 1056 Fred Flintstone 817263

014 Prime Suspect £2.00 27/08/04 28/08/04 1097 Annette Kirkton 384756

015 Shrek £1.50 10/09/04 11/09/04 1034 Joan Silver 142536

Page 25: Database Systems

More than one table

but there’s a problem…

DVD Code Title Cost Date Out Date Due

002 Finding Nemo £2.50 03/09/04 04/09/04

003 American Pie 3 £2.50 01/09/04 02/09/04

008 The Pianist £2.50 04/09/04 06/09/04

011 Notting Hill £2.50 04/09/04 06/09/04

014 Prime Suspect £2.00 27/08/04 28/08/04

015 Shrek £1.50 10/09/04 11/09/04

003 American Pie 3 £2.50 27/08/04 28/08/04

011 Notting Hill £2.50 27/08/94 28/08/04

Member Number

MemberName

Telephone Number

1012 Isobel Ringer 293847

1034 John Silver 142536

1056 Fred Flintstone 817263

1097 Annette Kirton 384756

Page 26: Database Systems

More than one table

DVD Code Title Cost Date Out Date Due

002 Finding Nemo £2.50 03/09/04 04/09/04

003 American Pie 3 £2.50 01/09/04 02/09/04

008 The Pianist £2.50 04/09/04 06/09/04

011 Notting Hill £2.50 04/09/04 06/09/04

014 Prime Suspect £2.00 27/08/04 28/08/04

015 Shrek £1.50 10/09/04 11/09/04

003 American Pie 3 £2.50 27/08/04 28/08/04

011 Notting Hill £2.50 27/08/94 28/08/04

Member Number Member NameTelephone Number DVD Code

1012 Isobel Ringer 293847 003

1034 John Silver 142536 ?

1056 Fred Flintstone 817263 011

1097 Annette Kirton 384756 ?

Page 27: Database Systems

More than one table

DVD Code Title Cost Date Out Date Due Member Number

002 Finding Nemo £2.50 03/09/04 04/09/04 1034

003 American Pie 3 £2.50 01/09/04 02/09/04 1012

008 The Pianist £2.50 04/09/04 06/09/04 1097

011 Notting Hill £2.50 04/09/04 06/09/04 1056

014 Prime Suspect £2.00 27/08/04 28/08/04 1097

015 Shrek £1.50 10/09/04 11/09/04 1034

Member Number Member NameTelephone Number

1012 Isobel Ringer 293847

1034 John Silver 142536

1056 Fred Flintstone 817263

1097 Annette Kirton 384756

Page 28: Database Systems

Keys A key is a field, or set of fields, whose

values uniquely identify a record. In any table, there may be more than

one field, or set of fields, which can uniquely identify each record—these are called candidate keys.

The candidate key which is chosen to be used is called the primary key.

Page 29: Database Systems

Keys

Member Number Member NameTelephone Number

1012 Isobel Ringer 293847

1034 John Silver 142536

1056 Fred Flintstone 817263

1097 Annette Kirton 384756

Member Number is a candidate key for the Member entity

Member Number is the chosen primary key for the Member entity

Page 30: Database Systems

Keys

MEMBER (Member Number, Name, Telephone Number)

MEMBER (Member NumberNameTelephone Number )

Page 31: Database Systems

KeysDVD Code Title Cost Date Out Date Due Member Number

002 Finding Nemo £2.50 03/09/04 04/09/04 1034

003 American Pie 3 £2.50 01/09/04 02/09/04 1012

008 The Pianist £2.50 04/09/04 06/09/04 1097

011 Notting Hill £2.50 04/09/04 06/09/04 1056

014 Prime Suspect £2.00 27/08/04 28/08/04 1097

015 Shrek £1.50 10/09/04 11/09/04 1034

DVD Code and Member Number is a candidate key for the DVD Rental entity

DVD Code and Member Number is the chosen primary key for the DVD Rental entity ( this is a compound key )

Member Number is called a foreign key.

Page 32: Database Systems

Keys

DVD RENTAL (DVD Code, Title, Cost, Date Out, Date Due, Member Number*)

DVD RENTAL (DVD CodeTitle CostDate OutDate DueMember Number*)

Page 33: Database Systems

Keys A foreign key is a field which is not a

primary key in its own table, but is a primary key in another table.

Member Number is a foreign key in the DVD table, because it is the primary key in the Member table and is used to link the two tables.

Page 34: Database Systems

Data ModelMEMBER (Member Number

NameTelephone Number )

DVD RENTAL (DVD CodeTitle CostDate OutDate DueMember Number*)

Page 35: Database Systems

Implementation

3 steps: Set-up the tables Populate the tables Manipulate and present the data

Page 36: Database Systems

Setting up the tables

Which tables are required? Which fields are required? What are the properties of each

field?

Page 37: Database Systems

Setting up the tables

Which tables are required? The tables correspond directly to

the entities in the data model. In this case, there will be two

tables, Member and DVD Rental.

Page 38: Database Systems

Setting up the tables

Which fields are required? The fields in each table are the

attributes in each entity in the data model.

Page 39: Database Systems

Setting up the tables What are the properties of each field?

Its name sensible be consistent!

Page 40: Database Systems

Setting up the tables What are the properties of each field?

Its name Its data type

text numeric (integer, real, currency) date or time Boolean (yes or no) link object

Page 41: Database Systems

Setting up the tables What are the properties of each field?

Its name Its data type Validation:

Presence check Restricted Choice check Range check

Page 42: Database Systems

Populating the tables

Take care to be accurate Validation

makes sure the data is sensible Verification

makes sure the data is correct

Page 43: Database Systems

Manipulating the Data

Searching records Sorting records Calculating values Presenting results

Page 44: Database Systems

Searching Which fields will be used to identify

the records required? What are the search conditions for

identifying the records required? Which fields will be displayed? E.g. Search for Test 3 = 10 “Test 3 = 10” is called the search

condition

Page 45: Database Systems

Searching: Boolean operators

Operator Meaning Example

= equal to Age = 16Surname = “Smith”

< > not equal to Height < > 1.70Certificate < > “PG”

>greater than

orafter

Age > 17Surname > “N”Date of Birth > 01/05/1952

<less than

orbefore

Height < 1.9Surname < “N”Date of Birth < 31/06/1990

>=greater than or equal to

orafter and including

Age >= 17Postcode >= “EH30”Date of Birth >= 01/05/1952

<=less than or equal to

orbefore and including

Height <= 1.95Postcode <= “EH20”Date of Birth <= 30/06/1990

Page 46: Database Systems

Searching: wildcard characters

Page 47: Database Systems

Searching: wildcard characters

Character Description Example

* Matches any number of characters (zero or more). It can be used as the first or last character in the character string.

wh* matches what, when, where, who, why, white, etc.

? Matches any single alphabetic character. b?ll matches ball, bell, bill and bull

[ ] Matches any single character within the brackets. b[ae]ll matches ball and bell but not bill or bull

! Matches any character not in the brackets. b[!ae]ll matches bill and bull but not ball or bell

– Matches any one of a range of characters. You must specify the range in ascending order (A to Z, not Z to A).

b[a-c]d matches bad, bbd, and bcd

# Matches any single numeric character. 1#3 matches 103, 113, 123, etc.

Page 48: Database Systems

Wildcard Searches Search for Surname = “*son”

Page 49: Database Systems

Complex Searches

A complex search involves more than one search condition (and usually more than one field)

Search for Test 3 = 10 AND Average > 6 Search for Test 3 = 10 OR Average > 6 Search for Test 3 > 5 AND Test 3 < 8 Search for Test 3 < 2 OR Test 3 >9

Page 50: Database Systems

Sorting

Which field will be used to decide the order of records? This is called the sort key.

For the sort key, will the order of sorting be ascending or descending?

Page 51: Database Systems

Sorting For a list of people with the tallest

first sort in descending order of height

For a list of people with youngest first sort in ascending order of age

For alphabetical order sort in ascending order of surname

“ascending order of surname” is called the sort condition

Page 52: Database Systems

Complex Sorting A complex sort involves more than

one sort condition involving two or more fields.

The main sort key is called the primary sort key, and the second one is called the secondary sort key.

“Telephone book” order: Ascending order of Surname, then

Ascending order of Forename

Page 53: Database Systems

Calculating

Use formulas or expressions to calculate a value for a record based on other values in the record

Page 54: Database Systems

Presenting

Use Layouts (Filemaker Pro) Use forms and reports (Microsoft

Access) Which fields are required? Perform a search and/or sorting

operation and present the results