SlideShare a Scribd company logo
Database Design
David Kelleher
www.davidk.net
Database Design
Database Model: Entities and Attributes
Implemented (MySQL): Tables and Fields or Columns
Unnormalized Example
Attribute Record #1 Record #2
Car ID 1382 1399
Make & Model Porsche GT3 Bentley Continental GT3
Year of Manufacture 2005 2014
Miles 16,556 16,556
Color White White
Prior Owner #1 Montgomery Burns
Prior Owner #2 Waylon Smithers
Price $79,990 $190,625
Buyer’s Name Marjorie Bouvier Marge Simpson
Buyer’s Phone 555-3283 555-8707
Primary Keys
Uniquely Identifies Record
Be careful.
Social Security Number isn’t a good primary key:
• Could change after identity theft
• Might be reused over time
• Doesn’t exist for all users
• Has privacy issues
Normalization
Model and normalize your entities to avoid
redundancies, anomalies, and other errors
"Each of the normal forms is defined in a very
cryptic way; even when put into layman’s terms,
they can still be confounding." - Larry Ullman
First Normal Form
• Each attribute contains only 1 value
• Entities cannot have repeating groups of data
First Normal Form
Bad – Is Not 1NF
Car Entity
Car ID
Make & Model
Year of Manufacture
Miles
Color
Prior Owner #1
Prior Owner #2
Price
Buyer’s Name
Buyer’s Phone
First Normal Form
Better – Is 1NF
Car Entity
Car ID
Make
Model
Year of Manufacture
Miles
Color
Price
Buyer’s First Name
Buyer’s Last Name
Buyer’s Phone
Prior Owner Entity
Owner ID
Car ID
First Name
Last Name
Functional Dependency
The value of an attribute should be determined by
the primary key, and only by the primary key
For example, specific information about a car
(make, model, prior owners) can be determined by
looking up the VIN number. So those attributes are
functionally dependent on the VIN number key.
Functional Dependency
If an entity’s attributes are not functionally
dependent on the primary key, these problems
occur:
• Repeating, redundant entries in fields
• Update anomalies
Second Normal Form
• If the primary key is a composite key consisting of
multiple attributes, other attributes must not be
functionally dependent on just a subset of the
primary key
http://www.bkent.net/Doc/simple5.htm
Composite Key
The primary key, identifying a specific card, is a
composite of two attributes – the Rank and Suit.
Attribute Record #1 Record #2 Record #3 Record #4
Card Rank Jack Seven Queen Queen
Card Suit Spades Hearts Hearts Diamonds
Point Value 10 7 10 10
Second Normal Form
Bad – Is Not 2NF
Playing Card Entity
Card Rank
Card Suit
Point Value
Second Normal Form
Better – Is 2NF
Playing Card Entity
Card Rank
Card Suit
Card Rank Entity
Card Rank
Point Value
Note:
The primary key of the playing card entity is
still a composite of the Card Rank ID and
Card Suit
Second Normal Form
Also OK – Is 2NF
Playing Card Entity
Card ID
Rank
Suit
Point Value
MySQL developers usually add
surrogate primary keys (“IDs”)
to every entity instead of using
natural primary keys (real world
attributes like VIN numbers)
While that doesn’t solve functional dependency problems,
entities with a single ID primary key always meet the
conditions for second normal form
Third Normal Form
• Attributes must be functionally dependent on the
primary key, and not on any other attributes
Find repeating entries & update anomalies:
Attribute Record #1 Record #2
Car ID 1382 1399
Make Porsche Bentley
Model GT3 GT3
Year of Manufacture 2005 2014
Miles 16,556 16,556
Color White White
Price $79,990 $190,625
Buyer’s First Name Marjorie Marge
Buyer’s Last Name Bouvier Simpson
Buyer’s Phone 555-3283 555-8707
Model with many-to-many relationships
Relationships
Many to many relationships are not allowed in
MySQL applications.
Create an intermediate entity with one-to-many
relationships between the primary keys of the two
entities.
Third Normal Form
Take a Deep Breath…
Don’t worry so much about whether a functional
dependency problem is a 2nd normal form issue or a
3rd normal form issue.
Just make sure you fix both types of problems.
Functional Dependency Pledge
“Every non-key attribute must provide a fact about
the key, the whole key, and nothing but the key....
so help me Codd*”
*E.F. Codd was the inventor of Relational Databases
and normalization
Indexes Save the Day!
• Where clause
• Order By clause
• Joins
Delete Anomalies
In our car database model, if you delete records
from the make, model, or person table, foreign
keys would be orphaned in other tables.
Delete Anomalies
Foreign Key Constraints
Foreign key constraints can be created in the
database implementation, with two approaches:
• Prevent the delete of a record where its primary
key exists as a foreign key in another table.
• Cascade the delete of a record, removing linked
records from the other tables
Soft Deletes
Instead of deleting records from a database, you
could:
• Add an active attribute. Updating your queries to
only select active records will hide the records
you no longer want to show.
• Move the records to an archival table.
Inner vs Outer Join
Inner joins are done to select records that have
entries linked to records in all joined tables.
Outer joins are done to select all records, whether
or not they are linked to the joined tables.
Database Design
David Kelleher
www.davidk.net

More Related Content

Similar to Database Design and Normalization

Geek Sync | Looking "Normal" and Seeing "Stars": Table Designs Working Together
Geek Sync | Looking "Normal" and Seeing "Stars": Table Designs Working TogetherGeek Sync | Looking "Normal" and Seeing "Stars": Table Designs Working Together
Geek Sync | Looking "Normal" and Seeing "Stars": Table Designs Working Together
IDERA Software
 
DBMS:Relational Modal
DBMS:Relational ModalDBMS:Relational Modal
DBMS:Relational Modal
VaishnaviVaishnavi17
 
Karen Lopez 10 Physical Data Modeling Blunders
Karen Lopez 10 Physical Data Modeling BlundersKaren Lopez 10 Physical Data Modeling Blunders
Karen Lopez 10 Physical Data Modeling Blunders
Karen Lopez
 
3 where are my keys - sql explore
3   where are my keys - sql explore3   where are my keys - sql explore
3 where are my keys - sql explore
sqlserver.co.il
 
Understanding indices
Understanding indicesUnderstanding indices
Understanding indices
Richard Douglas
 
Rulette : A pragmatic business rule management library
Rulette : A pragmatic business rule management libraryRulette : A pragmatic business rule management library
Rulette : A pragmatic business rule management library
Kislay Verma
 
Index the obvious and not so obvious
Index the obvious and not so obviousIndex the obvious and not so obvious
Index the obvious and not so obvious
Harry Zheng
 
1RUNNING HEAD Normalization2NormalizationNORM.docx
1RUNNING HEAD Normalization2NormalizationNORM.docx1RUNNING HEAD Normalization2NormalizationNORM.docx
1RUNNING HEAD Normalization2NormalizationNORM.docx
drennanmicah
 
ER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdfER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdf
SadiaSharmin40
 
Database models unit 1 part 2
Database models unit 1  part 2Database models unit 1  part 2
Database models unit 1 part 2
Ram Paliwal
 
10 things to avoid in data model 09242010
10 things to avoid in data model 0924201010 things to avoid in data model 09242010
10 things to avoid in data model 09242010
ERwin Modeling
 
Understanding optistruct & LS-Dyna files using text editor
Understanding optistruct & LS-Dyna files using text editorUnderstanding optistruct & LS-Dyna files using text editor
Understanding optistruct & LS-Dyna files using text editor
Akshay Mistri
 
Encryption and Tokenization: Friend or Foe?
Encryption and Tokenization: Friend or Foe?Encryption and Tokenization: Friend or Foe?
Encryption and Tokenization: Friend or Foe?
Zach Gardner
 
Advanced data modeling
Advanced data modelingAdvanced data modeling
Advanced data modeling
Dhani Ahmad
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Matters
dclsocialmedia
 
Oscar Engineering part 1
Oscar Engineering part 1Oscar Engineering part 1
Oscar Engineering part 1
Kirshenbaum Bond Senecal + Partners
 
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Citus Data
 
Data Con LA 2022 - Open Source Large Knowledge Graph Factory
Data Con LA 2022 - Open Source Large Knowledge Graph FactoryData Con LA 2022 - Open Source Large Knowledge Graph Factory
Data Con LA 2022 - Open Source Large Knowledge Graph Factory
Data Con LA
 
SQL Pass Architecture SQL Tips & Tricks
SQL Pass Architecture SQL Tips & TricksSQL Pass Architecture SQL Tips & Tricks
SQL Pass Architecture SQL Tips & Tricks
Ike Ellis
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
 

Similar to Database Design and Normalization (20)

Geek Sync | Looking "Normal" and Seeing "Stars": Table Designs Working Together
Geek Sync | Looking "Normal" and Seeing "Stars": Table Designs Working TogetherGeek Sync | Looking "Normal" and Seeing "Stars": Table Designs Working Together
Geek Sync | Looking "Normal" and Seeing "Stars": Table Designs Working Together
 
DBMS:Relational Modal
DBMS:Relational ModalDBMS:Relational Modal
DBMS:Relational Modal
 
Karen Lopez 10 Physical Data Modeling Blunders
Karen Lopez 10 Physical Data Modeling BlundersKaren Lopez 10 Physical Data Modeling Blunders
Karen Lopez 10 Physical Data Modeling Blunders
 
3 where are my keys - sql explore
3   where are my keys - sql explore3   where are my keys - sql explore
3 where are my keys - sql explore
 
Understanding indices
Understanding indicesUnderstanding indices
Understanding indices
 
Rulette : A pragmatic business rule management library
Rulette : A pragmatic business rule management libraryRulette : A pragmatic business rule management library
Rulette : A pragmatic business rule management library
 
Index the obvious and not so obvious
Index the obvious and not so obviousIndex the obvious and not so obvious
Index the obvious and not so obvious
 
1RUNNING HEAD Normalization2NormalizationNORM.docx
1RUNNING HEAD Normalization2NormalizationNORM.docx1RUNNING HEAD Normalization2NormalizationNORM.docx
1RUNNING HEAD Normalization2NormalizationNORM.docx
 
ER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdfER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdf
 
Database models unit 1 part 2
Database models unit 1  part 2Database models unit 1  part 2
Database models unit 1 part 2
 
10 things to avoid in data model 09242010
10 things to avoid in data model 0924201010 things to avoid in data model 09242010
10 things to avoid in data model 09242010
 
Understanding optistruct & LS-Dyna files using text editor
Understanding optistruct & LS-Dyna files using text editorUnderstanding optistruct & LS-Dyna files using text editor
Understanding optistruct & LS-Dyna files using text editor
 
Encryption and Tokenization: Friend or Foe?
Encryption and Tokenization: Friend or Foe?Encryption and Tokenization: Friend or Foe?
Encryption and Tokenization: Friend or Foe?
 
Advanced data modeling
Advanced data modelingAdvanced data modeling
Advanced data modeling
 
Metadata Matters
Metadata MattersMetadata Matters
Metadata Matters
 
Oscar Engineering part 1
Oscar Engineering part 1Oscar Engineering part 1
Oscar Engineering part 1
 
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
 
Data Con LA 2022 - Open Source Large Knowledge Graph Factory
Data Con LA 2022 - Open Source Large Knowledge Graph FactoryData Con LA 2022 - Open Source Large Knowledge Graph Factory
Data Con LA 2022 - Open Source Large Knowledge Graph Factory
 
SQL Pass Architecture SQL Tips & Tricks
SQL Pass Architecture SQL Tips & TricksSQL Pass Architecture SQL Tips & Tricks
SQL Pass Architecture SQL Tips & Tricks
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
 

More from Dave Kelleher

Uml Diagrams for Web Developers
Uml Diagrams for Web DevelopersUml Diagrams for Web Developers
Uml Diagrams for Web Developers
Dave Kelleher
 
Semantic HTML5 and JSON-LD
Semantic HTML5 and JSON-LDSemantic HTML5 and JSON-LD
Semantic HTML5 and JSON-LD
Dave Kelleher
 
Really Fast HTML5 Game Development with CreateJS
Really Fast HTML5 Game Development with CreateJSReally Fast HTML5 Game Development with CreateJS
Really Fast HTML5 Game Development with CreateJS
Dave Kelleher
 
Debugging PHP Code
Debugging PHP CodeDebugging PHP Code
Debugging PHP Code
Dave Kelleher
 
Cinematic UX Design
Cinematic UX DesignCinematic UX Design
Cinematic UX Design
Dave Kelleher
 
Cryptocurrencies
CryptocurrenciesCryptocurrencies
Cryptocurrencies
Dave Kelleher
 
Cinematic UX Design
Cinematic UX DesignCinematic UX Design
Cinematic UX Design
Dave Kelleher
 
Semantic HTML5 and Microdata
Semantic HTML5 and MicrodataSemantic HTML5 and Microdata
Semantic HTML5 and Microdata
Dave Kelleher
 
Reverse Card Sort for UX Testing
Reverse Card Sort for UX TestingReverse Card Sort for UX Testing
Reverse Card Sort for UX Testing
Dave Kelleher
 

More from Dave Kelleher (9)

Uml Diagrams for Web Developers
Uml Diagrams for Web DevelopersUml Diagrams for Web Developers
Uml Diagrams for Web Developers
 
Semantic HTML5 and JSON-LD
Semantic HTML5 and JSON-LDSemantic HTML5 and JSON-LD
Semantic HTML5 and JSON-LD
 
Really Fast HTML5 Game Development with CreateJS
Really Fast HTML5 Game Development with CreateJSReally Fast HTML5 Game Development with CreateJS
Really Fast HTML5 Game Development with CreateJS
 
Debugging PHP Code
Debugging PHP CodeDebugging PHP Code
Debugging PHP Code
 
Cinematic UX Design
Cinematic UX DesignCinematic UX Design
Cinematic UX Design
 
Cryptocurrencies
CryptocurrenciesCryptocurrencies
Cryptocurrencies
 
Cinematic UX Design
Cinematic UX DesignCinematic UX Design
Cinematic UX Design
 
Semantic HTML5 and Microdata
Semantic HTML5 and MicrodataSemantic HTML5 and Microdata
Semantic HTML5 and Microdata
 
Reverse Card Sort for UX Testing
Reverse Card Sort for UX TestingReverse Card Sort for UX Testing
Reverse Card Sort for UX Testing
 

Recently uploaded

Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 

Recently uploaded (20)

Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 

Database Design and Normalization

  • 2. Database Design Database Model: Entities and Attributes Implemented (MySQL): Tables and Fields or Columns
  • 3. Unnormalized Example Attribute Record #1 Record #2 Car ID 1382 1399 Make & Model Porsche GT3 Bentley Continental GT3 Year of Manufacture 2005 2014 Miles 16,556 16,556 Color White White Prior Owner #1 Montgomery Burns Prior Owner #2 Waylon Smithers Price $79,990 $190,625 Buyer’s Name Marjorie Bouvier Marge Simpson Buyer’s Phone 555-3283 555-8707
  • 4. Primary Keys Uniquely Identifies Record Be careful. Social Security Number isn’t a good primary key: • Could change after identity theft • Might be reused over time • Doesn’t exist for all users • Has privacy issues
  • 5. Normalization Model and normalize your entities to avoid redundancies, anomalies, and other errors "Each of the normal forms is defined in a very cryptic way; even when put into layman’s terms, they can still be confounding." - Larry Ullman
  • 6. First Normal Form • Each attribute contains only 1 value • Entities cannot have repeating groups of data
  • 7. First Normal Form Bad – Is Not 1NF Car Entity Car ID Make & Model Year of Manufacture Miles Color Prior Owner #1 Prior Owner #2 Price Buyer’s Name Buyer’s Phone
  • 8. First Normal Form Better – Is 1NF Car Entity Car ID Make Model Year of Manufacture Miles Color Price Buyer’s First Name Buyer’s Last Name Buyer’s Phone Prior Owner Entity Owner ID Car ID First Name Last Name
  • 9. Functional Dependency The value of an attribute should be determined by the primary key, and only by the primary key For example, specific information about a car (make, model, prior owners) can be determined by looking up the VIN number. So those attributes are functionally dependent on the VIN number key.
  • 10. Functional Dependency If an entity’s attributes are not functionally dependent on the primary key, these problems occur: • Repeating, redundant entries in fields • Update anomalies
  • 11. Second Normal Form • If the primary key is a composite key consisting of multiple attributes, other attributes must not be functionally dependent on just a subset of the primary key http://www.bkent.net/Doc/simple5.htm
  • 12. Composite Key The primary key, identifying a specific card, is a composite of two attributes – the Rank and Suit. Attribute Record #1 Record #2 Record #3 Record #4 Card Rank Jack Seven Queen Queen Card Suit Spades Hearts Hearts Diamonds Point Value 10 7 10 10
  • 13. Second Normal Form Bad – Is Not 2NF Playing Card Entity Card Rank Card Suit Point Value
  • 14. Second Normal Form Better – Is 2NF Playing Card Entity Card Rank Card Suit Card Rank Entity Card Rank Point Value Note: The primary key of the playing card entity is still a composite of the Card Rank ID and Card Suit
  • 15. Second Normal Form Also OK – Is 2NF Playing Card Entity Card ID Rank Suit Point Value MySQL developers usually add surrogate primary keys (“IDs”) to every entity instead of using natural primary keys (real world attributes like VIN numbers) While that doesn’t solve functional dependency problems, entities with a single ID primary key always meet the conditions for second normal form
  • 16. Third Normal Form • Attributes must be functionally dependent on the primary key, and not on any other attributes
  • 17. Find repeating entries & update anomalies: Attribute Record #1 Record #2 Car ID 1382 1399 Make Porsche Bentley Model GT3 GT3 Year of Manufacture 2005 2014 Miles 16,556 16,556 Color White White Price $79,990 $190,625 Buyer’s First Name Marjorie Marge Buyer’s Last Name Bouvier Simpson Buyer’s Phone 555-3283 555-8707
  • 18. Model with many-to-many relationships
  • 19. Relationships Many to many relationships are not allowed in MySQL applications. Create an intermediate entity with one-to-many relationships between the primary keys of the two entities.
  • 21. Take a Deep Breath… Don’t worry so much about whether a functional dependency problem is a 2nd normal form issue or a 3rd normal form issue. Just make sure you fix both types of problems.
  • 22. Functional Dependency Pledge “Every non-key attribute must provide a fact about the key, the whole key, and nothing but the key.... so help me Codd*” *E.F. Codd was the inventor of Relational Databases and normalization
  • 23. Indexes Save the Day! • Where clause • Order By clause • Joins
  • 24. Delete Anomalies In our car database model, if you delete records from the make, model, or person table, foreign keys would be orphaned in other tables.
  • 26. Foreign Key Constraints Foreign key constraints can be created in the database implementation, with two approaches: • Prevent the delete of a record where its primary key exists as a foreign key in another table. • Cascade the delete of a record, removing linked records from the other tables
  • 27. Soft Deletes Instead of deleting records from a database, you could: • Add an active attribute. Updating your queries to only select active records will hide the records you no longer want to show. • Move the records to an archival table.
  • 28. Inner vs Outer Join Inner joins are done to select records that have entries linked to records in all joined tables. Outer joins are done to select all records, whether or not they are linked to the joined tables.