Database Systems A guide to producing a fully functional RDBMS.

113
Database Systems A guide to producing a fully functional RDBMS

Transcript of Database Systems A guide to producing a fully functional RDBMS.

Page 1: Database Systems A guide to producing a fully functional RDBMS.

Database Systems

A guide to producing a

fully functional

RDBMS

Page 2: Database Systems A guide to producing a fully functional RDBMS.

How Can this Presentation Help Me?

If you work through this presentation use the terminology quoted and produce all the diagrams and documentation mentioned throughout this presentation, you will have succeeded in meeting most of the requirements necessary to produce a successful report on the analysis, design and implementation of a Relational Database.

Do not move on from one section to the next until you fully understand and can apply the concepts

described in this presentation

Page 3: Database Systems A guide to producing a fully functional RDBMS.

Contents

Theory and terminology

The Analysis Phase

• Requirements Definition

• Functional Dependency & Relationships

• Normalisation

• Entity Relationship Diagrams

• Data Dictionaries & Data Types

• Functions [Input, Processes & Outputs]

The Design Phase

The Implementation Phase

Page 4: Database Systems A guide to producing a fully functional RDBMS.

• Data – A collection of raw facts and figures

• Information – Final product created from the raw data after processing

• Database – A collection of related information organised in a

structured way to allow easy retrieval of any one item

Some Terminology

Page 5: Database Systems A guide to producing a fully functional RDBMS.

Table – A complete set of data. Also known as an entity or relation

Record – One row of the table

Field – One column of the table. Also known as an attribute

Elements of a database

Types of Database

Flat file Database – Single table

Relational Database – Multi table

Page 6: Database Systems A guide to producing a fully functional RDBMS.

Flat-file Database – Single table

A telephone directory is an

example of a flat file database

Problems with flat-file databases

• Redundant Data

Data is repeated and hence stored many times. This wastes disk space and slows down query time.

• Typographical Errors

Greater likelihood of errors when data is being entered.

Page 7: Database Systems A guide to producing a fully functional RDBMS.

Problems with flat-file databases

• Updating Data

Every occurrence of a piece of data will have to be updated if its value changes

• Modifying Data

If a record is deleted this may destroy all reference to a particular piece of data

To overcome these problems it is better to store data in multiple tables i.e. a Relational

database

Page 8: Database Systems A guide to producing a fully functional RDBMS.

Characteristics of a

relational database

• Data is stored in a set of tables

• Tables are joined by relational

links

• Reduces duplication of data in

database - Normalisation

• Allows greater flexibility and

efficiency

Page 9: Database Systems A guide to producing a fully functional RDBMS.

Relational Database – Multi table

The data is stored in multiple tables. This is the most common way of keeping a computerised

database

• Each table must have a unique reference for each record which is called the Primary key

• Replicating these into other tables creates the Foreign key

• These foreign keys form the Relationships that link the tables together

Page 10: Database Systems A guide to producing a fully functional RDBMS.

Relational Database – Multi table

• Redundant Data

The disk space required to store data is reduced and queries can be performed more quickly.

• Typographical Errors

As data is only entered once the chances of these errors occurring are greatly reduced..

Page 11: Database Systems A guide to producing a fully functional RDBMS.

Relational Database – Multi table

• Updating Data

Data need only be updated once as it would only have been entered once

• Modifying Data

Problems of the kind mentioned earlier disappear. New records will simply have their attributes added to the relevant table

Page 12: Database Systems A guide to producing a fully functional RDBMS.

Database Management System [DBMS]

• DBMS

A computer program or collection of computer programs that provides the necessary tools to create and manipulate the data in a database

• RDBMS

Relational Database Management Systems are used to create and manipulate relational databases e.g.

- Microsoft Access

- Oracle

- Lotus Approach

Page 13: Database Systems A guide to producing a fully functional RDBMS.

Database Systems -

Construct a data model of an existing, non computerised

system

THE ANALYSIS PHASE

Page 14: Database Systems A guide to producing a fully functional RDBMS.

Database Systems

Analysis Phase

• Requirements Definition• Normalisation• Entity-Relationship Diagrams• Data Dictionaries• Functions

Page 15: Database Systems A guide to producing a fully functional RDBMS.

Database Systems

Analysis

• Requirements Definition• Normalisation• Entity-Relationship Diagrams• Data Dictionaries• Functions

Page 16: Database Systems A guide to producing a fully functional RDBMS.

Requirements Definition

When we normalise any type of database system we need to know what the data in the system means. Therefore we either have to talk to the people who use the existing system or we have to be supplied with very detailed information about how the system works and the data stored within it.The following slide shows an example of some current data.

Below this are listed some questions that help establish the requirements of the new system.

Can you think of anything else the analyst might ask?

Page 17: Database Systems A guide to producing a fully functional RDBMS.

Requirements DefinitionSalespersonNumber

SalespersonName

SalesArea

CustomerNumber

CustomerName

WarehouseNumber

WarehouseLocation

SalesAmount

3462 Walters West 187651883019242

Delta SystemsA.Levy & SonsRainer & Co.

433

FargoBismarkBismark

13540106009700

3593 Dryne East 188411889919565

R.W.Flood I nc.Seward SystemsStodola's I nc.

221

SuperiorSuperiorPlymouth

1156025908800

• Does each salesperson have their own sales area?• Does each customer deal with only one salesperson ?• Does each customer only receive goods from one warehouse?

The answer to these questions will influence how we structurethe database system.

The answer to these questions and others make up theRequirements Definition

Page 18: Database Systems A guide to producing a fully functional RDBMS.

Database Systems

Analysis

• Requirements Definition• Normalisation• Entity-Relationship Diagrams• Data Dictionaries• Functions

Page 19: Database Systems A guide to producing a fully functional RDBMS.

Functional Dependency

Functional dependency means that there must be only a one-to-one dependency for each attribute mapped from a primary key to that attribute.

For example, the engine number of a car [Primary Key] can only have engine capacity as an attribute of that key creating Functional Dependency

BUTA particular engine capacity can be associated with the engine numbers of many makes of car. This does not give rise to Functional Dependency

It defines a relationship in which the existence of one entity/attribute is entirely dependent on the existence of another (one-to-one).

Page 20: Database Systems A guide to producing a fully functional RDBMS.

Functional Dependency - Practical Example

Order Number is the primary key.

The value for each attribute of SALES,except Item Price, depends upon the valueof the primary key.

All attributes of SALES, except Item Price,are Functionally Dependent on theprimary key

Item Price is Functionally Dependent on thethe attribute Item

Page 21: Database Systems A guide to producing a fully functional RDBMS.

Relationships

Having established a definition for the term Functional Dependency we now need to explore the different types of relationships that can exist between attributes in different entities:

There are 3 types of relationships that can exist:

• One to One Relationships

• One to Many Relationships

• Many to Many Relationships

Now lets take a closer look at each of these on the next slides

Page 22: Database Systems A guide to producing a fully functional RDBMS.

Entity Relationships

One-to-oneA blind person owns a guide dog which is exclusively theirs.

J. Smith

B. Jones

A. Gray

Rover

Pippa

Patch

Page 23: Database Systems A guide to producing a fully functional RDBMS.

Entity Relationships

One-to-manyA doctor may have many patients, but a patient is assigned to only one doctor.

Dr Ache

Dr Payne

Grant

Allan

Mark

Jane

Amy

Page 24: Database Systems A guide to producing a fully functional RDBMS.

Entity Relationships

Many-to-manyA film may have many stars and each star may act in many films.

Film X

Film Y

Star A

Star B

Star C

Page 25: Database Systems A guide to producing a fully functional RDBMS.

Important Note:An RDBMS system cannot produce a robust solution if two or more of the entities have a many to many relationship

To overcome this problem it is necessary to introduce another entity thus creating One to Many relationships between itself and the offending entities

This can become a common occurrence when you are working with larger and more complex database systems

Page 26: Database Systems A guide to producing a fully functional RDBMS.

Now you should have the tools and understanding you require in order to normalise the data in order that a solution can be produced using an RDBMS [Relational Database Management System]

Please take your time when working through the next part of this presentation and revisit it again and again until you are completely comfortable with the concepts involved

Normalisation of the data is perhaps the single most important aspect of developing a robust solution to any database problem!

Page 27: Database Systems A guide to producing a fully functional RDBMS.

Normalisation• Normalisation is a 'fancy' term for a set of rules, designed to make sure that a database is organised in the best way

possible

• This allows the data to be processed more efficiently and any query to be processed.

• These rules depend on relationships being established between the entities to create a functional dependency between them.

Page 28: Database Systems A guide to producing a fully functional RDBMS.

The normalisation process involves:

• Finding and grouping together all the entities and their attributes.

• Removing repeating groups of data. – This is another way of saying that there is no point in

storing a persons' name and details etc. in many different places within a database.

• Providing unique keys for each entity in the database system. – You need to have a way of making sure that when

you delete 'Paul Smith' from the Transactions entity that it is the correct person.

Page 29: Database Systems A guide to producing a fully functional RDBMS.

The Three Major Stages of Normalisation:

• First Normal Form– 1NF is the first level of normalisation. An entity

(table) is in First Normal form if it contains no repeating attributes (fields) or groups of attributes.

• Second Normal Form– An entity is in 2NF if no attribute (not part of the

primary key) is dependent on only part of the primary key. This only applies to entities with concatenated primary keys.

• Third Normal Form– An entity is in 3NF if all attributes are entirely

dependent on the primary key and not on any attribute that is not part of the primary key.

Page 30: Database Systems A guide to producing a fully functional RDBMS.

To produce a set of entities in First Normal Form (1NF):

• Remove repeating (multiple) groups within the primary entities (tables) so that each record (row) within the entity is the same length.

• Repeating groups then become new entities, linked together by a one-to-many relationship.

• Relationships are created by including a primary key from one entity as a foreign key in another entity

Page 31: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

OrderNo.

Acc.No.

Customer Address Date I tem Qty. I temPrice

TotalCost

7823 178 Daisy's Café 27 Bay Drive,Cove

16/ 7 BakewellTart

20 0.15 12.35

DanishPastry

13 0.20

Apple Pie 45 0.15

4633 526 Smiths 12 Dee View,Aberdeen

16/ 7 Butteries 120 0.20 24.00

2276 167 Sally'sSnacks

3 High Street,Banchory

17/ 7 Apple Pie 130 0.15 56.50

CherryPie

100 0.18

Steak Pie 30 0.50

MeringuePie

20 0.20

1788 032 Tasty Bite 17 Wood Place,I nsch

18/ 7 Apple Pie 15 0.15 7.50

DanishPastry

50 0.20

Page 32: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

OrderNo.

Acc.No.

Customer Address Date I tem Qty. I temPrice

TotalCost

7823 178 Daisy's Café 27 Bay Drive,Cove

16/ 7 BakewellTart

20 0.15 12.35

DanishPastry

13 0.20

Apple Pie 45 0.15

4633 526 Smiths 12 Dee View,Aberdeen

16/ 7 Butteries 120 0.20 24.00

2276 167 Sally'sSnacks

3 High Street,Banchory

17/ 7 Apple Pie 130 0.15 56.50

CherryPie

100 0.18

Steak Pie 30 0.50

MeringuePie

20 0.20

1788 032 Tasty Bite 17 Wood Place,I nsch

18/ 7 Apple Pie 15 0.15 7.50

DanishPastry

50 0.20

Page 33: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

Items Purchased

Orders

Page 34: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

Items Purchased

Orders

Page 35: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

Order No. can be used to uniquely identify each record and cantherefore be made the primary key.

Orders (Order No.Acc. No. Customer Address Date Total Cost)

Orders Table:

Page 36: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

Items Purchased Table:

No one attribute can be used touniquely identify a record.

Order No. and Item together canuniquely identify a record.

Concatenated key is required

Items (*Order No.Purchased Item

Quantity Item Price)

Page 37: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker ShopFirst Normal Form

Items (*Order No.Purchased Item

Quantity Item Price

Orders (Order No.Acc. No. Customer Address Date Total Cost)

Page 38: Database Systems A guide to producing a fully functional RDBMS.

The Three Major Stages of Normalisation:

• First Normal Form– 1NF is the first level of normalisation. An entity

(table) is in First Normal form if it contains no repeating attributes (fields) or groups of attributes.

• Second Normal Form– An entity is in 2NF if no attribute (not part of the

primary key) is dependent on only part of the primary key. This only applies to entries with concatenated primary keys.

• Third Normal Form– An entity is in 3NF if all attributes are entirely

dependent on the primary key and not on any attribute that is not part of the primary key.

Page 39: Database Systems A guide to producing a fully functional RDBMS.

To produce a set of entities in Second Normal Form (2NF):

• Test for dependency by testing each particular attribute in turn to check that it can be uniquely identified by making use of all the primary key. This test need not be completed unless you have at least one table which requires a concatenated Primary Key

• Remove all partially dependent attributes to a new entity.

N.B. – A concatenated key occurs when you need two fields together in order to uniquely identify a record

Page 40: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker ShopFirst Normal Form

Items (*Order No.Purchased Item

Quantity Item Price)

Orders (Order No. Acc. No. Customer Address Date Total Cost)

Page 41: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

Because this entity has a single attribute as the primary keythere can be no partial dependencies and therefore the entityis already in 2NF.

Orders Table:

Page 42: Database Systems A guide to producing a fully functional RDBMS.

Primary Key Attribute Functionally Dependent?

Charlie’s Baker Shop(2NF Step 1)

Items Purchased Table:Primary key is Order No. and Item

Test for dependency by testing eachparticular attribute.

Page 43: Database Systems A guide to producing a fully functional RDBMS.

Primary Key Attribute Functionally Dependent?

Order No Quantity YESItem Quantity is functionally dependent

on Order No. and Item.

Charlie’s Baker Shop(2NF Step 1)

Items Purchased Table:Primary key is Order No. and Item

Test for dependency by testing eachparticular attribute.

Page 44: Database Systems A guide to producing a fully functional RDBMS.

Primary Key Attribute Functionally Dependent?

Order No Item Price NOItem Item price is functionally dependent

Item, but not on Order No. and Item

Order No Quantity YESItem Quantity is functionally dependent

on Order No. and Item.

Charlie’s Baker Shop(2NF Step 1)

Items Purchased Table:Primary key is Order No. and Item

Test for dependency by testing eachparticular attribute.

Page 45: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop(2NF Step 2)

Remove any partially dependent attributes to a new entity

Page 46: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop(2NF Step 2)

Part Order Price List

Remove any partially dependent attributes to a new entity

Page 47: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop(2NF Step 2)

Part Order

Create a relationship between the tables

Primary Key: ItemPrimary Key: Order No. and *Item

and assign Primary Keys

Price List

Page 48: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker ShopSecond Normal Form

Price List (Item Item Price)

Orders (Order No. Acc. No. Customer Address Date Total Cost)

Part Order (*Order No. *Item Quantity)

Page 49: Database Systems A guide to producing a fully functional RDBMS.

The Three Major Stages of Normalisation:

• First Normal Form– 1NF is the first level of normalisation. An entity

(table) is in First Normal form if it contains no repeating attributes (fields) or groups of attributes.

• Second Normal Form– An entity is in 2NF if no attribute (not part of the

primary key) is dependent on only part of the primary key. This only applies to entries with concatenated primary keys.

• Third Normal Form– An entity is in 3NF if all attributes are entirely

dependent on the primary key and not on any attribute that is not part of the primary key.

Page 50: Database Systems A guide to producing a fully functional RDBMS.

To produce a set of entities in Third Normal Form (3NF):

• Test each attribute in turn to check for dependency on the primary key.

• Remove all transitive dependencies to a new entity.– A transitive dependency is where an attribute is

dependent on another attribute (or attributes) that is (are) NOT the primary key

Page 51: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker ShopSecond Normal Form

Price List (Item Item Price)

Orders (Order No. Acc. No. Customer Address Date Total Cost)

Part Order (*Order No. *Item Quantity)

Page 52: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop - 3NF Step1

Test fordependency

Primary Key Attribute Trasnsitive Dependency

Page 53: Database Systems A guide to producing a fully functional RDBMS.

Primary Key Attribute Trasnsitive Dependency

Order No. Acc.No. YES: Acc.No can be f ound if we know eitherCustomer or Address

Charlie’s Baker Shop - 3NF Step1

Test fordependency

Page 54: Database Systems A guide to producing a fully functional RDBMS.

Primary Key Attribute Trasnsitive Dependency

Order No. Acc.No. YES: Customer can be f ound if we know eitherAcc.No. or Address

Order No. Customer YES Customer can be f ound if we know eitherAcc.No. or Address

Charlie’s Baker Shop - 3NF Step1

Test fordependency

Page 55: Database Systems A guide to producing a fully functional RDBMS.

Primary Key Attribute Trasnsitive Dependency

Order No. Acc.No. YES: Customer can be f ound if we know eitherAcc.No. or Address

Order No. Customer YES Acc.No. can be f ound if we know eitherCustomer or Address

Order No. Address YES Address can be f ound if we know eitherCustomer or Acc.No

Charlie’s Baker Shop - 3NF Step1

Test fordependency

Page 56: Database Systems A guide to producing a fully functional RDBMS.

Primary Key Attribute Trasnsitive Dependency

Order No. Acc.No. YES: Customer can be f ound if we know eitherAcc.No. or Address

Order No. Customer YES Acc.No. can be f ound if we know eitherCustomer or Address

Order No. Address YES Address can be f ound if we know eitherCustomer or Acc.No

Order No. Date NO Dependent on Order No.

Charlie’s Baker Shop - 3NF Step1

Test fordependency

Page 57: Database Systems A guide to producing a fully functional RDBMS.

Primary Key Attribute Trasnsitive Dependency

Order No. Acc.No. YES: Customer can be f ound if we know eitherAcc.No. or Address

Order No. Customer YES Acc.No. can be f ound if we know eitherCustomer or Address

Order No. Address YES Address can be f ound if we know eitherCustomer or Acc.No

Order No. Date NO Dependent on Order No.

Order No. Total Cost NO Dependent on Order No.

Charlie’s Baker Shop - 3NF Step1

Test fordependency

Page 58: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop - 3NF Step2

Remove transitive dependencies to a new entity

Page 59: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop - 3NF Step2

Orders Customers

Remove transitive dependencies to a new entity

Page 60: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop - 3NF Step2

Create a relationship between the tables

Orders Customers

and assign Primary Keys

Primary Key:Order No.

Primary Key:Acc.No.

Page 61: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker ShopThird Normal Form

Normalisation Complete

Orders (Order No.*Acc. No. Date Total Cost)

Price List (Item Item Price)

Part Order (*Order No. *Item Quantity)

Customers (Acc. No. Customer Address)

Page 62: Database Systems A guide to producing a fully functional RDBMS.

Normalisation -

1. Remove repeating groups to create a new entity

2. Create a relationship using one of the attributes that are left [Usually the primary key]3.‘Check out’ entities with concatenated keys. If any attribute is not fully dependent on both parts of the primary key remove it to create a new entity.

4. Create a relationship using one of the attributes that are left [Usually the primary key]5.‘Check out’ every entity. If any attribute is dependent on any attribute other than the primary key, remove it into a new entity.

6. Create a relationship using one of the attributes

Page 63: Database Systems A guide to producing a fully functional RDBMS.

Database Systems

Analysis

• Requirements Definition• Normalisation• Entity-Relationship Diagrams• Data Dictionaries• Functions

Page 64: Database Systems A guide to producing a fully functional RDBMS.

Entity - Relationship Diagrams

• E-R diagrams show the structure of the data to

be modelled.

• They are a convenient method for

representing the relationships, entities and

attributes in a system.

• This is done by illustrating a system with a

diagram to produce a detailed specification for

each entity and the attributes within them.

Page 65: Database Systems A guide to producing a fully functional RDBMS.

Symbols used in an E – R diagram

Entity – a collection of data [table]

Attribute – a data item in an

entity [field]

ENTITY

ATTRIBUTE

Page 66: Database Systems A guide to producing a fully functional RDBMS.

Symbols used in an E – R diagram

Relationship – a description of the link between two entities.

Key Attribute – a data item which makes up the primary key or part of it.

KEY ATTRIBUTE

RELATIONSHIP

Page 67: Database Systems A guide to producing a fully functional RDBMS.

Simple Examples

1. A blind person owns a guide dog

Guide DogBlind Person owns

PatientsDoctor treats

1 M

1 1

2. A doctor treats many patients

Page 68: Database Systems A guide to producing a fully functional RDBMS.

Simple Examples

3. A film may have many stars and

each star may be in many films.

StarsFilm hasM N

Page 69: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker ShopThird Normal Form

Orders (Order No.*Acc. No. Date Total Cost)

Price List (Item Item Price)

Part Order (*Order No. *Item Quantity)

Customers (Acc. No. Customer Address)

Page 70: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

Price List has

1 M

1 M

1

M

1. Determine the relationships between the

entities.

contains

Part Order

places

Customers Orders

Page 71: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker ShopThird Normal Form

Orders (Order No. *Acc. No. Date Total Cost)

Price List (Item Item Price)

Part Order (*Order No. *Item Quantity)

Customers (Acc. No. Customer Address)

Page 72: Database Systems A guide to producing a fully functional RDBMS.

2. List the attributes alongside

each entity

Order No

*Acc. No

Date

Total Cost

Address

Customer

Acc.No

*Order No

*Item

Quantity

Price List has

places

Customers Orders

1 M

1 M

1

M

contains

Part Order

Item

Item Price

Charlie’s Baker Shop

Page 73: Database Systems A guide to producing a fully functional RDBMS.

Database Systems

Analysis

• Requirements Definition• Normalisation• Entity-Relationship Diagrams• Data Dictionaries• Functions

Page 74: Database Systems A guide to producing a fully functional RDBMS.

Data Dictionary

• A data dictionary is a database about a database and is often called metadata [data about data]

• It is created at the analysis stage to provide a record of the attributes and their properties:

- Data type

- Required [or not] I.e. Can this field be left blank ?

- Range

- Format

• When the database is up and running it acts as a useful reference

Page 75: Database Systems A guide to producing a fully functional RDBMS.

Data Types

Text

A text attribute only stores letters from the standard 26 character alphabet

Number

Used to hold numeric data. Remember to show the range of numbers to be stored [ Use common sense]

Text and Number

Used for alphanumeric data e.g. An address that may contain a house number and street name.

Page 76: Database Systems A guide to producing a fully functional RDBMS.

Data Types

Date

Dates can be laid out using various formats. Two common formats are short (dd/mm/yy) or (dd/mm/yyyy) and long (month day, year)

Time

Various formats can be used here. A time of day, a duration, 24-Hr clock, am/pm etc.

Boolean

These are binary values only having two states. True/false, yes/no or off/on.

Page 77: Database Systems A guide to producing a fully functional RDBMS.

Data Types

The data types and formats used at

this stage will be general and will be

mapped on to those available in the

RDBMS [Relational Database

Management System] in the design

phase.

Page 78: Database Systems A guide to producing a fully functional RDBMS.

Data Dictionary for Charlie’s Baker Shop

Entity Attribute DescriptionOrder No Unique I dentifier. Numbers in the range 1-

99999 required

Acc.No Unique I dentifier. Numbers in the range 1-99999 required

Date Short Form dd/ mm/ yy

Orders

Total Cost Cost of total order; Value up to £9999.99required.

Acc.No Unique I dentifier. See Orders entity

Customer Company Name required; text only

Customers

Address All address details f or customer incl postcoderequired. Text & Numbers

I tem Unique I dentifier. Numbers in the range 1-9999required

Price List

I tem Price Cost of item; Value up to £99.99 required

Order No Unique I dentifier. See Orders entity

I tem Unique I dentifier. See I tem entity

Part Order

Quantity Numbers in the range 1-999 required

Page 79: Database Systems A guide to producing a fully functional RDBMS.

Database Systems

Analysis

• Requirements Definition• Normalisation• Entity-Relationship Diagrams• Data Dictionaries• Functions

Page 80: Database Systems A guide to producing a fully functional RDBMS.

FunctionsA function is anything that acts on

the data in a database system and is classified as input, process or

output.• Input

An input is a function that places new data in the system such as creating, updating or deleting data

• Process

An automated function within the database system e.g. automatic update of an attribute, checking the particular value of an attribute, changing or calculating new values from the data

Page 81: Database Systems A guide to producing a fully functional RDBMS.

Functions• Output

A function that produces data from the database system e.g. a report, letter or summary of the data

Beyond these Operational functions modern computerised database systems can

provide a wide range of Strategic and Tactical information which can assist with planning and organising e.g. queries and

ordered lists can provide the Company with invaluable marketing information

Page 82: Database Systems A guide to producing a fully functional RDBMS.

Listed Functions that affect each entity of the Charlie’s Baker Shop

databaseEntity Input Process Output

Orders Add a new order.Update an order.

List all orders

Customers Add a new customerUpdate a customersdetailsDelete a customersdetails

List all customerswith outstandingorders

Price List Add a new itemDelete an item

List items andcorrespondingprices

PartOrder

Add quantity of anitem orderedAmend the quantity ofan item ordered

Automaticallyupdate total costof an order

List all orderscontaining aparticular itemList all customersordering aparticular item

Page 83: Database Systems A guide to producing a fully functional RDBMS.

Database Systems -

Design database structures to represent

the data model

THE DESIGN PHASE

Page 84: Database Systems A guide to producing a fully functional RDBMS.

Database Systems-Design Phase

Database Structure and item names relate to the data model

Unique keys are chosen for all Database structures

Validity checks represent the data model

Data item characteristics represent the data model Designed structures are appropriate to the intended implementation method

Page 85: Database Systems A guide to producing a fully functional RDBMS.

Database Systems-Design Phase

Database Structure and item names relate to the data model

Unique keys are chosen for all Database structures

Validity checks represent the data model

Data item characteristics represent the data model

Designed structures are appropriate to the intended implementation method

Page 86: Database Systems A guide to producing a fully functional RDBMS.

The conceptual design [Data Model or E- R Diagram] has already been created in the analysis phase using Entities, Relationships and Attributes

The entities now become tables and the relationships between these entities are preserved between the tables

Most RDBMS have syntactical rules that govern how fields and tables are named. This may affect how we construct the field and table names.

Page 87: Database Systems A guide to producing a fully functional RDBMS.

Database Systems-Design Phase Database Structure and item names

relate to the data model Unique keys are chosen for all

Database structures Validity checks represent the data

model Data item characteristics represent the

data model Designed structures are appropriate to the intended implementation method

Page 88: Database Systems A guide to producing a fully functional RDBMS.

Indexes

The keys chosen for the database structures are the same as those identified in the data model. These remember were established during the normalisation process

Some RDBMS include tools that create indexes of fields to speed up searches

within the database.

However, only Primary and Foreign keys should normally be indexed to help speed

up this process.

Page 89: Database Systems A guide to producing a fully functional RDBMS.

Database Systems-Design Phase Database Structure and item names

relate to the data model Unique keys are chosen for all

Database structures Validity checks represent the data

model Data item characteristics represent the

data model Designed structures are appropriate to the intended implementation method

Page 90: Database Systems A guide to producing a fully functional RDBMS.

Data entered into the database should be valid and correct. Most RDBMS contain tools which will offer 3 types of validity check

PRESENCE

Checks to see if a value is present or not. E.g. if a field value must be set, a presence check would be carried out on it.

RANGE

Checks to see if a value entered is within a prescribed range.

RESTRICTED CHOICE

This would ensure that the user only entered data that corresponded to a list of pre-set values e.g. N S E or W

Page 91: Database Systems A guide to producing a fully functional RDBMS.

Database Systems-Design Phase Database Structure and item names

relate to the data model Unique keys are chosen for all

Database structures Validity checks represent the data

model Data item characteristics represent the

data model Designed structures are appropriate to the intended implementation method

Page 92: Database Systems A guide to producing a fully functional RDBMS.

Every RDBMS has its own set of data types that it can implement.

In the design phase we create a more

detailed data dictionary that identifies the

field types, sizes, keys and validity checks

that can be implemented in the RDBMS

Page 93: Database Systems A guide to producing a fully functional RDBMS.

Fieldname Type Size Validation Format Req'd I ndexOrder No Autonumber Size Yes Yes (Unique)

Primary KeyAcc. No Number Auto Yes NoCustomer Text 35 Yes NoAddress1 Text 50 Yes NoAddress2 Text 50 No NoAddress3 Text 50 Yes NoPostcode Text 8 XX9?_9XX Yes NoDate Date/ Time Auto Short Date Yes NoTotal Cost Currency Auto >=£10.00 £99.99 Yes No

Database : Charlie’s Baker Shop

Table : Orders

Also refers to tables that foreign keys have come from

Page 94: Database Systems A guide to producing a fully functional RDBMS.

Database Systems-Design Phase Database Structure and item

names relate to the data model Unique keys are chosen for all

Database structures Validity checks represent the data

model Data item characteristics represent the data model Designed structures are appropriate to the intended implementation method

Page 95: Database Systems A guide to producing a fully functional RDBMS.

State the relationships that will be implemented using the RDBMS. These should be the same as for the E-R diagram.

However, in the design phase we show the relationships between the primary and foreign key fields in each table.

Relationships

Page 96: Database Systems A guide to producing a fully functional RDBMS.

Charlie’s Baker Shop

[Customers.Acc.No.] 1: M

[Orders.Acc.No.]

Price List (Item Item Price)

Part Order (*Order No. *Item Quantity)

Orders (Order No.*Acc. No. Date Total Cost)

Customers (Acc. No. Customer Address)

[Orders.Order No] 1: M [Part Order.Order No]

[Price List.Item] 1: M [Part Order.Item]

Page 97: Database Systems A guide to producing a fully functional RDBMS.

When you are designing the

database structures for your

implementation you must always

consider what your RDBMS is

capable of doing.

There is no point designing a system

that cannot be implemented with the

software that you have available.

Page 98: Database Systems A guide to producing a fully functional RDBMS.

Database Systems -

Implement a designed database structure based on

an existing system

THE IMPLEMENTATION PHASE

Page 99: Database Systems A guide to producing a fully functional RDBMS.

Database Systems Implementation

Phase Correctly implement database structures from design

Perform data manipulations effectively

Carry out queries to meet given criteria efficiently

Produce reports to meet given specifications

Evaluate the database structure against the existing system

Ensure data is well managed and secure

Page 100: Database Systems A guide to producing a fully functional RDBMS.

Database Systems Implementation

Phase Correctly implement database structures from design

Perform data manipulations effectively

Carry out queries to meet given criteria efficiently

Produce reports to meet given specifications

Evaluate the database structure against the existing system

Ensure data is well managed and secure

Page 101: Database Systems A guide to producing a fully functional RDBMS.

Using the chosen RDBMS each of the tables within your design including all the relevant fields will be specified and established.

Implement all the features of your detailed data dictionary i.e.

Table names Fieldnames and whether indexed or not Validity checks Primary/foreign keys

Once and only once the structure has been established, is it possible to enter data into the

tables

Page 102: Database Systems A guide to producing a fully functional RDBMS.

Database Systems Implementation

Phase Correctly implement database structures from design

Perform data manipulations effectively

Carry out queries to meet given criteria efficiently

Produce reports to meet given specifications

Evaluate the database structure against the existing system

Ensure data is well managed and secure

Page 103: Database Systems A guide to producing a fully functional RDBMS.

EDITAn edit manipulation involves the user changing data already present in the database  SORTA sort manipulation takes a range of data from the database and sorts it on the values in one or more fields  INSERTAn insert manipulation involves the user adding new data to tables within the database  DELETEA delete manipulation involves the user removing data from tables within the database

Page 104: Database Systems A guide to producing a fully functional RDBMS.

Database Systems Implementation

Phase Correctly implement database structures from design

Perform data manipulations effectively

Carry out queries to meet given criteria efficiently

Produce reports to meet given specifications

Evaluate the database structure against the existing system

Ensure data is well managed and secure

Page 105: Database Systems A guide to producing a fully functional RDBMS.

Queries are questions you can ask of the data in tables within the database. They are similar to searches you

would perform within a flat-file database Queries create subsets of the data within the database by field, record or both A query performed on a relational database will always produce a table A query can be performed on more than one table because the relationships between primary and foreign keys link the tables together Queries not only produce subsets of the data, but can be used to perform mathematical operations on this data

Base Tables – The original table that the query acted upon

Answer Tables – The table created by the query. This contains a subset of the data from the base table/s

Page 106: Database Systems A guide to producing a fully functional RDBMS.

TextualQueries that act on fields of the text data type  NumericQueries that act on fields of the numeric data type  ExactFinds a specific match on a field for particular criteria e.g. customers with surname ‘Smith’.  InexactLooks for values within a range in a particular field e.g. customers with names beginning with 'S'  Combinations of search criteriaUses a combination of criteria e.g. All customers who ordered items costing <£1.50

Styles of Query

Page 107: Database Systems A guide to producing a fully functional RDBMS.

Different tools have been developed to allow us to query a relational database through the RDBMS

  Graphical ToolsAllow us to select and enter the details for the query graphically e.g. The tool you are using in Microsoft Access  Structured Query Language [SQL]A recognised international standard for creating queries for relational databases e.g. 

SELECT DISTINCT [Orders].[Acc.No.], Sum([Orders].[Total Cost]) AS [SumOfTotal Cost]FROM [Orders]GROUP BY [Orders].[Acc.No.];

Often, an RDBMS will use both types of tool. Inexperienced users would use the graphical

tool Experienced users would use SQL

Page 108: Database Systems A guide to producing a fully functional RDBMS.

Database Systems Implementation

Phase Correctly implement database structures from design

Perform data manipulations effectively

Carry out queries to meet given criteria efficiently

Produce reports to meet given specifications

Evaluate the database structure against the existing system

Ensure data is well managed and secure

Page 109: Database Systems A guide to producing a fully functional RDBMS.

A report is like a query in that it can summarise

the data in the database. However reports are

used to produce printed output [ Hard Copy]

e.g. The user may require a listing of all

customers and their addresses from the database

Reports

N.B. When producing reports using MS Access it is possible to perform some basic statistical analysis on the data if the data type is numeric

Page 110: Database Systems A guide to producing a fully functional RDBMS.

Database Systems Implementation

Phase Correctly implement database structures from design

Perform data manipulations effectively

Carry out queries to meet given criteria efficiently

Produce reports to meet given specifications

Evaluate the database structure against the existing system

Ensure data is well managed and secure

Page 111: Database Systems A guide to producing a fully functional RDBMS.

When the relational database has been produced an evaluationevaluation should be performed against the existing system to identify any

improvements and a report compiled to include the following:

Information summary of how the existing system is used outlining restrictions of this system and limited usage

Improvements in the efficiency and effectiveness of the new system e.g. Reduction in entry and storage of duplicate data

Automation of operations such as producing reports

Saving in man hours for entering data and reduction in data entry errors

New facilities available through the new system such as reports that analyse the data statistically or queries that automate the production of summary data

Page 112: Database Systems A guide to producing a fully functional RDBMS.

Database Systems Implementation

Phase Correctly implement database structures from design

Perform data manipulations effectively

Carry out queries to meet given criteria efficiently

Produce reports to meet given specifications

Evaluate the database structure against the existing system

Ensure data is well managed and secure

Page 113: Database Systems A guide to producing a fully functional RDBMS.

Legislation – Your legal responsibilities  Data Protection Act (1998) Ensures that people who keep information on computer (Data Users) give rights to individuals (Data Subjects) who have information recorded about them on computer  Copyright, Design & Patents Act (1988) Most published material is protected by this act i.e. there are restrictions to the use you can make of such material in respect of copying selling and adapting it.  Computer Misuse Act (1990) This act provides regulations that govern the access to and use of computer systems and the information within them e.g. unauthorised use of another person's username and password.