+ All Categories
Home > Documents > A2 Computing

A2 Computing

Date post: 19-Jan-2016
Category:
Upload: hisa
View: 46 times
Download: 0 times
Share this document with a friend
Description:
A2 Computing. Lesson Databases - Introduction. Aims and Objectives. To understand what a relational database is To understand how to design a relational database using ER modelling To be able to construct a model of a new database using this technique. What is a database?. - PowerPoint PPT Presentation
Popular Tags:
23
A2 Computing Lesson Databases - Introduction
Transcript
Page 1: A2 Computing

A2 Computing

LessonDatabases - Introduction

Page 2: A2 Computing

Aims and Objectives

• To understand what a relational database is• To understand how to design a relational

database using ER modelling• To be able to construct a model of a new

database using this technique

Page 3: A2 Computing

What is a database?

• A structured collection of data

• Data is usually stored in tables

Surname: James

First name: Samantha

Date of Birth: 20.12.89

Address: 16 Poppy Close

Town: Southam

County: Warwickshire

Surname: Brown

First name: David

Date of Birth: 20.12.89

Address: 16 Poppy Close

Town: Southam

County: Warwickshire

Surname: Lastler

First name: David

Date of Birth: 20.12.89

Address: 16 Poppy Close

Town: Southam

County: Warwickshire

Surname: Whitefield

First name: Nina

Date of Birth: 21.02.76

Address: 16 Poppy Close

Town: Southam

County: Warwickshire

Page 4: A2 Computing

Flat Files A flat file is a database held in a single file consisting of one table.

Video no.

Title Country

Date release

d

Classification

Rental price

1 Lord of the Rings US 2001 12 3.50

2 Attack of the Clones

US 2002 PG 2.99

3 About a boy UK 2002 U 2.99

4 Crocodile Dundee AUS 1986 15 1.50

5 Die another day UK 2002 12 2.99

6 Shrek US 2001 U 1.99Record

Field File

Page 5: A2 Computing

Flat File problems

• There are a number of problems using flat files where everything is stored in one table– data is often repeated in several different places– as a result, updating of data is time consuming

and often inaccurate– data entry is time consuming and prone to errors

Page 6: A2 Computing

Using multiple tables

• Using a database with multiple tables (a relational database) means that data can be separated into a more structured design

• Data between tables is linked so that it is accessed only when required ( a relationship is established)

• Advantages– Reduces the repeating of data (redundant data)– Reduces error on updating and inputting of data– Increases the reliability of the database (data integrity)– Increases speed of data retrieval

Page 7: A2 Computing

Building a database

• Before a relational database can be built it needs to be designed so it works effectively and efficiently

• The data requirements are carefully analysed • A data model is built

– a method of describing the data, the structure and how it is interrelated, the constraints that apply

• You will be learning the process………

Page 8: A2 Computing

Entity-relationship modelling•An entity is:

–An object, person or a thing of interest represented in a database.

• Customers, Employees, Products, Orders.

•Each entity will normally be represented by a table in the relational database.

•Entity names are normally in the singular–Customer not Customers

Page 9: A2 Computing

• An attribute is:– The information held about an entity.– e.g. Customer attributes:

» Surname» Forname» Address» Phone number

• Attributes are normally stored in fields.

Entity-relationship modelling

Page 10: A2 Computing

Question - Entity or Attribute?

• Car model• Car• Colour• Registration number• Date of Registration• Cost

• Attribute• Entity• Attribute• Attribute• Attribute• Attribute

Page 11: A2 Computing

Car Table

Model Colour Date of Registration

Registration number

Cost

Passat Blue 31/01/06 AZ06 GNS £12,000

Golf Silver 01/08/05 AS56 CHA £11,500

Page 12: A2 Computing

Question

• A database is to store details of the following – students at college– A level courses

• Write down suitable entity names for these• For each entity write down possible attributes• Draw the database table that would represent

these details

Page 13: A2 Computing

Entity relationships

• The link between two entities is called a relationship.

• Often shown as a Diagram.Entity Relationship Diagrams (ER Diagrams)

CAR

OWNER

Page 14: A2 Computing

Types of relationships

• One to one (1:1)

• One to many (1:n or 1:*)

• Many to Many (n:n *:*)

MAN

WOMEN

Is married to

MOTHER CHILD

PATIENT

TREATMENT

STUDENT

CLASS

ORDER

PRODUCT

Page 15: A2 Computing

Question

• A car has one registered owner with the DVLA• One person may own several vehicles• Draw an entity-relationship diagram to

represent this

OWNER CARis owner of

CAR OWNERis owned by

Page 16: A2 Computing

Question

• It is possible for a blind person to be given one guide dog

• A guide dog will look after just one blind person

• Draw the entity-relationship diagram to represent this

BLIND PERSON GUIDE DOGkeeps

guidesGUIDE DOG BLIND PERSON

Page 17: A2 Computing

Question • An item can be ordered by a customer• A customer may order as many items as is

needed• An item may appear on orders made by

different customers• Draw an entity-relationship diagram to

represent the item and the order

ITEM ORDERappears on

ORDER ITEMconsists of

Page 18: A2 Computing

Dealing with many-to many relationships

• Many-to-many relationships cannot be implemented easily in a database

• It is important to break up many to many relationships by creating an extra entity

ORDER

ITEM

ORDER

ITEM

ORDERITEM New Entity

Page 19: A2 Computing

Question

• A library lends out books to borrowers• Each borrower may borrow several books• There may be more than one copy of a book• Each book title is identified by its ISBN• Each book copy is identified by a unique

number• Draw the entity-relationship diagram to

represent this system

Page 20: A2 Computing

Answer

BORROWER

BOOKTITLE

BOOKCOPY

has

Page 21: A2 Computing

Answer

BORROWER

BOOKTITLE

BOOKCOPY

LOAN

makes of

has

Page 22: A2 Computing

Summary

• A relational database can be modelled using an entity-relationship diagram

• There are four degrees of relationships– one to one (1:1)– many to one (n:1)– one to many (1:n)– many to many (n:n)

• many-to-many relationship should be broken up as they cannot easily be represented in a database

Page 23: A2 Computing

Glossary

Database: a structured collection of data

Entity: an object or thing of interest about which data is recorded

Relationship: an association or link between two entities

Data model: a method of describing the data, it’s structure and the way it is interrelated

Attribute: A piece of data recorded about an entity


Recommended