38
Database Design Normalisation – An introduction

Database Design Normalisation – An introduction

  • Upload
    thanh

  • View
    24

  • Download
    0

Embed Size (px)

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

Citation preview

Slide 1

Database Design

Normalisation An introductionKeys

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

TitleVersionGame of year editionDo these pieces of information uniquely identify this game?How else could we uniquely identify this game?GameID1202

No other game will have the same IDUnique identifiers for the game could be:Title + Version + Platform

GameIDor a combination of KeyComposite KeyWhat do we call the pieces of information that uniquely identify the game ?We can use keys to find game information from different sources:Game reviewsGame PricesTitle + Version + Platform

Title + Version + Platform

Entity Relationships

Gamer and game relationship ..SteveKimJo

Gamer:Games:How many games could Steve own?How many people could own Modern Warfare?1. This lesson will explore some simple logic gates and what they do;2. Before we get into the detail we first need to understand something about boolean variables;8Gamer to Games relationship: 1 gamer can have many games many gamers can have the same game GamerGame many to many relationship (n:n) What kind of relationship is this?1. This lesson will explore some simple logic gates and what they do;2. Before we get into the detail we first need to understand something about boolean variables;9Normalisation

Cars are designed to be ..

faster easy to maintain more efficient

Normalisation

improves our database design faster easy to maintain more efficient Steve, Jo and Kim write the list of games they want for xmas:

Modern Warfare 2Modern Warfare 2BioshockTomb RaiderTomb RaiderFable IIUsing these lists would you be able to buy the correct game & send it to the correct gamer?

KimSteve Jo

PlatformX360TitleModern Warfare 2GameID5426CompanyNameInfinity WardWhat additional game data might we need?:

Modern Warfare 2Modern Warfare 2BioshockTomb RaiderTomb RaiderFable IIWe need more information to identify the correct game:GameIDTitlePlatformCompany Name542654262112111070031110Modern Warfare 2Modern Warfare 2Fable IITomb RaiderBioshockTomb RaiderX360X360X360X360X360X360Infinity WardInfinity WardLionHeadEIDOS2KEIDOSGame list has information that uniquely identifies the game e.g. GameID

Modern Warfare 2Modern Warfare 2BioshockTomb RaiderTomb RaiderFable II1. This lesson will explore some simple logic gates and what they do;2. Before we get into the detail we first need to understand something about boolean variables;15Steve LonelyWhat additional gamer information might we need?:GamerID9089A unique GamerID would be ideal !!

Name23 Jan 1980DateofBirth

KimSteve JoWe need more information to identify the correct gamer:GamerIDNameDateofBirthSteve Lonely23 Jan 19809089Kim Newbie10 Mar 19913120Jo Headshot31 Dec 19687707Gamer list has information that uniquely identifies the gamer e.g. GamerID

KimSteve Jo1. This lesson will explore some simple logic gates and what they do;2. Before we get into the detail we first need to understand something about boolean variables;17

Can we now buy the correct game & send it to the correct gamer?GamerIDNameDateofBirthSteve Lonely23 Jan 19809089Kim Newbie10 Mar 19913120Jo Headshot31 Dec 19687707GameIDTitlePlatformCompany Name542654262112111070031110Modern Warfare 2Modern Warfare 2Fable IITomb RaiderBioshockTomb RaiderX360X360X360X360X360X360Infinity WardInfinity WardLionHeadEIDOS2KEIDOSWhich gamer wants which game?Steve wants 3 games for xmas

How could we rewrite this information on one note?

Modern Warfare 2BioshockTomb Raider

Steve

Steve - Modern Warfare, Bioshock, Tomb Raider Write all games in a line against Steves name .How do we add games to the list ?GamerIDNameDateofBirthSteve Lonely23 Jan 19809089This is called a repeating field GameID5426GameID1110GameID7003GameID1910GameID4410GameID2010GameID9910GameID12310GameID1210We could add games by adding more and more columns

Steve - Modern Warfare

Steve Bioshock

Steve - Tomb Raider Write Steves name against each game ..How do we add games to the list ?We could add games without adding more columns just dataGamerIDNameDateofBirthSteve Lonely23 Jan 19809089542611107003Steve Lonely23 Jan 19809089Steve Lonely23 Jan 19809089GameID

980Steve Lonely23 Jan 198090897720Steve Lonely23 Jan 19809089Steve Modern Warfare 2, Bioshock, Tomb RaiderWhich is the best way to join our lists together and why?Steve - Modern Warfare 2Steve - Bioshock Steve - Tomb RaiderOR Congratulations !!!Step 1 of the normalisation process

Avoid repeating fields when linking lists/tablesYou have just witnessedone of the great mysteries of the database universe !!

1. This lesson will explore some simple logic gates and what they do;2. Before we get into the detail we first need to understand something about boolean variables;251. This lesson will explore some simple logic gates and what they do;2. Before we get into the detail we first need to understand something about boolean variables;26Lets see this work against our data?

GamerIDNameDateofBirthSteve Lonely23 Jan 19809089

GameIDTitlePlatformCompany Name542611107003Modern Warfare 2Tomb RaiderBioshockX360X360X360Infinity WardEIDOS2KWe have a link is there a problem?GameID5426Can we improve our repeating field design?GamerIDNameDateofBirthGameIDKey field

GamerID

Repeating field

GameIDmake the repeating field part of the key GamerID

GameIDWe could add games without adding more columns just dataGamerIDNameDateofBirthSteve Lonely23 Jan 19809089542611107003Steve Lonely23 Jan 19809089Steve Lonely23 Jan 19809089GameID

980Steve Lonely23 Jan 198090897720Steve Lonely23 Jan 19809089Good design No repeating fields !!Are there any other great mysteries ? Step 2 of the normalisation processnon key fields should depend upon all parts of the key

1. This lesson will explore some simple logic gates and what they do;2. Before we get into the detail we first need to understand something about boolean variables;30non key fields Name, DateofBirth should depend upon all parts of the key GamerID & GameIDGamerIDNameDateofBirthSteve Lonely23 Jan 19809089542611107003Steve Lonely23 Jan 19809089Steve Lonely23 Jan 19809089GameID

980Steve Lonely23 Jan 198090897720Steve Lonely23 Jan 19809089Is 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 !!!! Move Name and DateofBirth to their own table? 542611107003GameID

9807720NameDateofBirthSteve Lonely23 Jan 1980Steve Lonely23 Jan 1980Steve Lonely23 Jan 1980Steve Lonely23 Jan 1980Steve Lonely23 Jan 1980GamerID908990899089

90899089GamerIDNameDateofBirthSteve Lonely23 Jan 19809089

But what about the GameID field? 542611107003GameID

9807720GameID needs to remain with the GamerID to keep the link between games and gamers Non key fields should depend upon all parts of the key ..GamerIDNameDateofBirthSteve Lonely23 Jan 19809089542611107003Steve Lonely23 Jan 19809089Steve Lonely23 Jan 19809089GameID

980Steve Lonely23 Jan 198090897720Steve Lonely23 Jan 19809089GamerIDNameDateofBirthSteve Lonely23 Jan 19809089

542611107003GameID9807720GamerID90899089908990899089

original table becomes

Is there anything else we can improve ?GamerIDNameDateofBirthSteve Lonely23 Jan 19809089

542611107003GameID9807720GamerID90899089908990899089

GameIDTitlePlatformCompany ID542611107003Modern Warfare 2Tomb RaiderBioshockX360X360X360432211205422980Dead SpaceX36009227720GOWX3608727Company NameInfinity WardEIDOS2KEAEPIC

Step 3 of the normalisation processThe final frontier remove non key dependenciesRemove non key dependencies an example GameIDTitlePlatformCompany ID5426Etc.7003Modern Warfare 2BioshockX360X36043225422Company NameInfinity Ward2K

CompanyName is dependent upon ComanyID not GameID Move CompanyName to its own tableRemove non key dependencies ?GameIDTitlePlatformCompany ID5426Etc.7003Modern Warfare 2BioshockX360X36043225422Company NameInfinity Ward2K

GameIDTitlePlatformCompany ID5426Etc.7003Modern Warfare 2BioshockX360X36043225422

Company ID43225422Company NameInfinity Ward2K

becomes 2 tablesTo boldly normalise