+ All Categories
Home > Documents > Database Design Normalisation – An introduction

Database Design Normalisation – An introduction

Date post: 16-Mar-2016
Category:
Upload: lee
View: 36 times
Download: 0 times
Share this document with a friend
Description:
Database Design Normalisation – An introduction. Keys. What list of information would you need to buy the correct game?. Platform. GameID. Title. PS3. 1202. Fallout 3. No other game will have the same ID. Version. Do these pieces of information uniquely identify this game?. - PowerPoint PPT Presentation
Popular Tags:
38
Database Design Normalisation – An introduction
Transcript
Page 1: Database Design Normalisation – An introduction

Database Design

Normalisation – An introduction

Page 2: Database Design Normalisation – An introduction

Keys

Page 3: Database Design Normalisation – An introduction

What list of information would you need to buy the correct game?

Page 4: Database Design Normalisation – An introduction

Platform

PS3Fallout 3

Title

Version

Game of year edition Do these pieces of

information uniquely identify this game?

How else could we uniquely identify

this game?

GameID

1202

No other game will have the same ID

Page 5: Database Design Normalisation – An introduction

Unique identifiers for the game could be:

Title + Version + Platform

GameID

or a combination of

Key

Composite Key

What do we call the pieces of information that uniquely

identify the game ?

Page 6: Database Design Normalisation – An introduction

We can use keys to find game information from different sources:

Game reviews

Game Prices

Title + Version

+ Platform

Title + Version

+ Platform

£

Page 7: Database Design Normalisation – An introduction

Entity Relationships

Page 8: Database Design Normalisation – An introduction

Gamer and game relationship ..

Steve Kim JoGamer:

Games:

How many games could Steve own?How many people could own Modern

Warfare”?

Page 9: Database Design Normalisation – An introduction

Gamer to Games relationship: 1 gamer can have many games

many gamers can have the same game

Gamer Game

many to many relationship (n:n)

What kind of relationship is this?

Page 10: Database Design Normalisation – An introduction

Normalisation

Page 11: Database Design Normalisation – An introduction

Cars are designed to be ..

faster easy to maintain

more efficient

Page 12: Database Design Normalisation – An introduction

Normalisation

… improves our database design …

faster easy to maintain

more efficient

Page 13: Database Design Normalisation – An introduction

Steve, Jo and Kim write the list of games they want for xmas:

Modern Warfare 2

Modern Warfare 2

BioshockTomb RaiderTomb Raider

Fable II

Using these lists would you be able to buy the correct game

& send it to the correct gamer?

KimSteve

Jo

Page 14: Database Design Normalisation – An introduction

Platform

X360

Title

Modern Warfare 2GameID

5426

CompanyName

Infinity Ward

What additional game data might we need?:

Modern Warfare 2Modern Warfare 2

BioshockTomb RaiderTomb Raider

Fable II

Page 15: Database Design Normalisation – An introduction

We need more information to identify the correct game:

GameID Title Platform Company Name

5426

5426

2112

1110

7003

1110

Modern Warfare 2

Modern Warfare 2

Fable II

Tomb Raider

Bioshock

Tomb Raider

X360

X360

X360

X360

X360

X360

Infinity Ward

Infinity Ward

LionHead

EIDOS

2K

EIDOS

Game list has information that uniquely identifies the game

e.g. GameID

Modern Warfare 2

Modern Warfare 2

BioshockTomb RaiderTomb Raider

Fable II

Page 16: Database Design Normalisation – An introduction

Steve Lonely

What additional gamer information might we need?:

GamerID

9089

A unique GamerID would

be ideal !!

Name

23 Jan 1980

DateofBirth

KimSteve

Jo

Page 17: Database Design Normalisation – An introduction

We need more information to identify the correct gamer:

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089

Kim Newbie 10 Mar 19913120

Jo Headshot 31 Dec 19687707

Gamer list has information that uniquely identifies the gamer

e.g. GamerID

KimSteve

Jo

Page 18: Database Design Normalisation – An introduction

Can we now buy the correct game & send it to the correct gamer?

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089

Kim Newbie 10 Mar 19913120

Jo Headshot 31 Dec 19687707

GameID Title Platform Company Name

5426

5426

2112

1110

7003

1110

Modern Warfare 2

Modern Warfare 2

Fable II

Tomb Raider

Bioshock

Tomb Raider

X360

X360

X360

X360

X360

X360

Infinity Ward

Infinity Ward

LionHead

EIDOS

2K

EIDOS

Which gamer wants which game?

Page 19: Database Design Normalisation – An introduction

Steve wants 3 games for xmas

How could we rewrite this information on one note?

Modern Warfare 2

BioshockTomb Raider

Steve

Page 20: Database Design Normalisation – An introduction

Steve - Modern Warfare, Bioshock, Tomb Raider

Write all games in a line against Steves name ….

How do we add games to the list ?

Page 21: Database Design Normalisation – An introduction

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089

This is called a ‘repeating’ field …

GameID

5426

GameID

1110

GameID

7003

GameID

1910

GameID

4410

GameID

2010

GameID

9910

GameID

12310

GameID

1210

We could add games by adding more and more columns …

Page 22: Database Design Normalisation – An introduction

Steve - Modern Warfare

Steve – Bioshock

Steve - Tomb Raider

Write Steves name against each game ..

How do we add games to the list ?

Page 23: Database Design Normalisation – An introduction

We could add games without adding more columns just data…

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089 5426

1110

7003Steve Lonely 23 Jan 19809089

Steve Lonely 23 Jan 19809089

GameID

980Steve Lonely 23 Jan 19809089

7720Steve Lonely 23 Jan 19809089

Page 24: Database Design Normalisation – An introduction

Steve – Modern Warfare 2, Bioshock, Tomb Raider…

Which is the best way to join our lists together and why?

Steve - Modern Warfare 2Steve - Bioshock

Steve - Tomb Raider

OR

Page 25: Database Design Normalisation – An introduction

Congratulations !!!

Step 1 of the normalisation process

‘Avoid repeating fields when linking lists/tables’

You have just witnessedone of the great mysteries of the database universe !!

Page 26: Database Design Normalisation – An introduction
Page 27: Database Design Normalisation – An introduction

Lets see this work against our data?

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089

GameID Title Platform Company Name

5426

1110

7003

Modern Warfare 2

Tomb Raider

Bioshock

X360

X360

X360

Infinity Ward

EIDOS

2K

We have a link – is there a problem?

GameID

5426

Page 28: Database Design Normalisation – An introduction

Can we improve our ‘repeating field’ design?

GamerID Name DateofBirth GameID

Key field

GamerID

Repeating field

GameID

make the repeating field part of the key …

GamerID GameID

Page 29: Database Design Normalisation – An introduction

We could add games without adding more columns just data…

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089 5426

1110

7003Steve Lonely 23 Jan 19809089

Steve Lonely 23 Jan 19809089

GameID

980Steve Lonely 23 Jan 19809089

7720Steve Lonely 23 Jan 19809089

Good design No repeating

fields !!

Page 30: Database Design Normalisation – An introduction

Are there any other great mysteries ?

Step 2 of the normalisation process

‘non key fields should depend upon all parts of the key’

Page 31: Database Design Normalisation – An introduction

non key fields ‘Name’, ‘DateofBirth’ should depend upon

all parts of the key ‘GamerID & GameID’

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089 5426

1110

7003Steve Lonely 23 Jan 19809089

Steve Lonely 23 Jan 19809089

GameID

980Steve Lonely 23 Jan 19809089

7720Steve Lonely 23 Jan 19809089

Is ‘DateofBirth’ Gamer data or Game data or

both?

Is ‘Name’ Gamer data or Game data or

both?

Gamer only !

(GamerID)

Gamer only !

(GamerID)

non key fields depend on just a bit of the key not all of it !!!

.. we can improve this design ..

… but whats the point …. ?

To remove all that duplicate data !!!!

Page 32: Database Design Normalisation – An introduction

Move ‘Name’ and ‘DateofBirth’ to their own table?

5426

1110

7003

GameID

980

7720

Name DateofBirth

Steve Lonely 23 Jan 1980

Steve Lonely 23 Jan 1980

Steve Lonely 23 Jan 1980

Steve Lonely 23 Jan 1980

Steve Lonely 23 Jan 1980

GamerID

9089

9089

9089

9089

9089

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089

But what about the GameID field?

5426

1110

7003

GameID

980

7720

GameID needs to remain with the GamerID to keep the link between games and gamers

Page 33: Database Design Normalisation – An introduction

Non key fields should depend upon all parts of the key ..

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089 5426

1110

7003Steve Lonely 23 Jan 19809089

Steve Lonely 23 Jan 19809089

GameID

980Steve Lonely 23 Jan 19809089

7720Steve Lonely 23 Jan 19809089

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089

5426

1110

7003

GameID

980

7720

GamerID

9089

9089

9089

9089

9089

original table

becomes

Page 34: Database Design Normalisation – An introduction

Is there anything else we can improve… ?

GamerID Name DateofBirth

Steve Lonely 23 Jan 19809089

5426

1110

7003

GameID

980

7720

GamerID

9089

9089

9089

9089

9089

GameID Title Platform Company ID

5426

1110

7003

Modern Warfare 2

Tomb Raider

Bioshock

X360

X360

X360

4322

1120

5422

980 Dead Space X360 0922

7720 GOW X360 8727

Company Name

Infinity Ward

EIDOS

2K

EA

EPIC

Page 35: Database Design Normalisation – An introduction

Step 3 of the normalisation process

The final frontier …

‘remove non key dependencies’

Page 36: Database Design Normalisation – An introduction

Remove non key dependencies… an example …

GameID Title Platform Company ID

5426

Etc.

7003

Modern Warfare 2

Bioshock

X360

X360

4322

5422

Company Name

Infinity Ward

2K

CompanyName is dependent

upon ComanyID

not GameID

Move CompanyName to

its own table

Page 37: Database Design Normalisation – An introduction

Remove non key dependencies… ?

GameID Title Platform Company ID

5426

Etc.

7003

Modern Warfare 2

Bioshock

X360

X360

4322

5422

Company Name

Infinity Ward

2K

GameID Title Platform Company ID

5426

Etc.

7003

Modern Warfare 2

Bioshock

X360

X360

4322

5422

Company ID

4322

5422

Company Name

Infinity Ward

2K

becomes 2 tables

Page 38: Database Design Normalisation – An introduction

To boldly normalise …


Recommended