SlideShare a Scribd company logo
Where Are My Keys?Ami Levin | CTO | DBSophic LTD
Session GoalsA revisit to some of the fundamental design principals of relational databases: Normalization rules, key selection, and the controversies associated with these issues from a very practical, hands-on perspective, with special emphasis on some surprising performance issues that may arise from sub-optimal selection of keys...
The Forefathers
Normalization“A relation whose domains are all simple can be represented in storage by a two-dimensional column homogeneous array of the kind discussed above. Some more complicated data structure is necessary for a relation with one or more non-simple domains. For this reason (and others to be cited below) the possibility of eliminating non-simple domains appears worth investigating. There is, in fact, a very simple elimination procedure, which we shall call…normalization”
1st Normal FormThere's no top-to-bottom or left-to-right ordering to the rows and columnsThere are no duplicate rowsEvery row-column intersection contains exactly one valueAll columns are regular
1st Normal Form
2nd Normal FormR is in 1st Normal Form (1NF).Given any candidate key K and any attribute A that is not a constituent of a candidate key, A depends upon the whole of K rather than just a part of it.
2nd Normal Form
3rd Normal FormR is in second normal form (2NF)Every non-prime attribute of R is non-transitively dependent on every candidate key of R.A transitive dependency is a functional dependency, in which X -> Z (X determines Z) indirectly, by virtue of X -> Y and Y -> Z.
3rd Normal Form
KeysSimpleComposite 	Candidate 	Primary	Artificial / Surrogate 	IntelligentNatural
The DebateTo ID or not to ID?IDENTITY (1,1) PK vs. Natural key
Pro ArtificialIn some cases, no natural key exists and an artificial key is the only option.Examples?
Pro ArtificialNatural keys can change. Artificial keys never change.How Often?Cascading referential constraintsArtificial keys can change
Pro ArtificialNatural keys may become very long and complex.Get longer with each level900 Bytes limit in SQL ServerMulti-column Joins
Pro ArtificialArtificial keys improve performance. Simpler join predicatesEver increasing clustering effectShort keys = Smaller DB = Faster (?)
Pro ArtificialArtificial keys reduce clustered index fragmentation. All types of artificial keys?Minimize maintenance down timeWhat about deletes?What about non-clustered indexes?
Pro NaturalNatural keys have business meaning.Artificial keys are logically never queried for
Pro NaturalQueries on tables using natural keys require fewer joins.The more familiar and meaningful the key, the less joins are required“Bypass” joins across levels
Pro NaturalData consistency is maintained explicitly when using natural keys.Artificial keys enable logical duplicates
Pro NaturalNatural keys eliminate potential physical clustering performance issues.Contention for clustered regions
Less Mentioned IssuesArtificial keys are the de-facto standard.ORM generate artificial keysLINQ doesn’t cache composite key rows
Less Mentioned IssuesData statistics and optimizations.Statistics on artificial keys are useless for parameter sniffingSelectivity estimations on composite key statistics are less accurate
Less Mentioned IssuesModularity and portability.Migration to other platformsMerging with other databases
Less Mentioned IssuesSimplicity and aesthetics.
Demo Design SpecURLCountry and city of ownerCountry ISO code needed by applicationData consistency is crucial
Natural vs. ArtificialDEMO
Ask Yourself…Is there a natural key that I can use as PK? Are there a few natural candidates? Which one is the simplest and most familiar?How stable is it?How will it be used logically?What will be the table physical usage patterns?What are the common query types for this table?
For More InformationA Relational Model of Data for Large Shared Data Banksby E. F. CODD.The Relational Model for Database Management: Version 2 by E.F. Codd. An introduction to database systemsby C.J Date. Database in Depth: Relational Theory for Practitionersby C.J Date.The Database Relational Model: A Retrospective Review and Analysisby C.J Date.Joe Celko's Data and Databases: Concepts in Practice by Joe Celko.Joe Celko's SQL for Smarties, Fourth Edition: Advanced SQL Programmingby Joe Celko.Database Modeling and Design, Fifth Edition: Logical Designby Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, and H.V. Jagadish.Pro SQL Server 2008 Relational Database Design and Implementationby Louis Davidson, Kevin Kline, Scott Klein, and Kurt Windisch.
Where Are My Keys?Q&A
3   where are my keys - sql explore

More Related Content

PDF
Microsoft SQL Server Relational Databases and Primary Keys
PPT
Database 3 Conceptual Modeling And Er
PPT
Database design
PDF
Dbms 10: Conversion of ER model to Relational Model
PPTX
Placement oriented data structures
PPT
Introductin to Data Modeling.
Microsoft SQL Server Relational Databases and Primary Keys
Database 3 Conceptual Modeling And Er
Database design
Dbms 10: Conversion of ER model to Relational Model
Placement oriented data structures
Introductin to Data Modeling.

What's hot (16)

PPT
Notesparadigms
PPTX
Database Design and Normalization
PPT
D4 Introduction to LINQ
PPT
Concept Based Search
PPTX
PPT
Relational Databases 2
PPT
Prolog ppt
DOC
Computer sec2-1st term
PDF
Effective Unsupervised Matching of Product Titles
PDF
Sec 2 1st term rev.
PDF
Zhongyuan Zhu - 2015 - Evaluating Neural Machine Translation in English-Japan...
PPTX
PPT
SystemT: Declarative Information Extraction
DOCX
Object relationship mapping and hibernate
PPT
Wipro technical interview questions
PPTX
Notesparadigms
Database Design and Normalization
D4 Introduction to LINQ
Concept Based Search
Relational Databases 2
Prolog ppt
Computer sec2-1st term
Effective Unsupervised Matching of Product Titles
Sec 2 1st term rev.
Zhongyuan Zhu - 2015 - Evaluating Neural Machine Translation in English-Japan...
SystemT: Declarative Information Extraction
Object relationship mapping and hibernate
Wipro technical interview questions
Ad

Viewers also liked (9)

PDF
3 extreme performance - databases acceleration using ssd
PPTX
Products.intro.forum version
PPTX
SQL Explore 2012: P&T Part 3
PPTX
DAC 2012
PPTX
Adi Sapir ISUG 123 11/10/2012
PPTX
Query handlingbytheserver
PPTX
Sql server user group news january 2013
PPTX
Things you can find in the plan cache
PDF
Windows azure sql_database_security_isug012013
3 extreme performance - databases acceleration using ssd
Products.intro.forum version
SQL Explore 2012: P&T Part 3
DAC 2012
Adi Sapir ISUG 123 11/10/2012
Query handlingbytheserver
Sql server user group news january 2013
Things you can find in the plan cache
Windows azure sql_database_security_isug012013
Ad

Similar to 3 where are my keys - sql explore (20)

PPT
Most frequently asked infosys technical interview questions and answers in 2018
PPTX
Avoiding common database pitfalls
PPSX
PPTX
NLIDB(Natural Language Interface to DataBases)
PPTX
Domain oriented development
PDF
Dare to build vertical design with relational data (Entity-Attribute-Value)
PDF
Prague data management meetup 2016-11-22
PDF
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
PPT
01 Persistence And Orm
DOCX
Mc0077 – advanced database systems
PDF
Cts informatica interview question answers
PDF
Intelligent query converter a domain independent interfacefor conversion
PPTX
The Importance of Data Analysis in Producing a Robust Physical Data Model
PPT
2006 DDD4: Data access layers - Convenience vs. Control and Performance?
PDF
Important Backend Concept for interview.
PPTX
Elegant and Efficient Database Design
PPTX
complete_DBMS_vtu_engineering presentation
PPTX
Why you shouldnt use django for that
PPTX
2. Relational_Data_Model_Keys_10b.pptx
PPT
Lecture 13
Most frequently asked infosys technical interview questions and answers in 2018
Avoiding common database pitfalls
NLIDB(Natural Language Interface to DataBases)
Domain oriented development
Dare to build vertical design with relational data (Entity-Attribute-Value)
Prague data management meetup 2016-11-22
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
01 Persistence And Orm
Mc0077 – advanced database systems
Cts informatica interview question answers
Intelligent query converter a domain independent interfacefor conversion
The Importance of Data Analysis in Producing a Robust Physical Data Model
2006 DDD4: Data access layers - Convenience vs. Control and Performance?
Important Backend Concept for interview.
Elegant and Efficient Database Design
complete_DBMS_vtu_engineering presentation
Why you shouldnt use django for that
2. Relational_Data_Model_Keys_10b.pptx
Lecture 13

More from sqlserver.co.il (20)

PPTX
SQL Explore 2012: P&T Part 2
PPTX
SQL Explore 2012: P&T Part 1
PPTX
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
PPTX
SQL Explore 2012 - Michael Zilberstein: ColumnStore
PPTX
SQL Explore 2012 - Meir Dudai: DAC
PPTX
SQL Explore 2012 - Aviad Deri: Spatial
PPTX
מיכאל
PPTX
נועם
PPTX
PPTX
מיכאל
PDF
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
PPTX
DBCC - Dubi Lebel
PPTX
Fast transition to sql server 2012 from mssql 2005 2008 for developers - Dav...
PPTX
ISUG 113: File stream
PDF
Extreme performance - IDF UG
PPTX
3 extreme performance - databases acceleration using ssd
PPTX
4 extreme performance - part ii
PPTX
2 extreme performance - smaller is better
PPTX
1 extreme performance - part i
PDF
6 sql explorer - powershell dba
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 1
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Aviad Deri: Spatial
מיכאל
נועם
מיכאל
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
DBCC - Dubi Lebel
Fast transition to sql server 2012 from mssql 2005 2008 for developers - Dav...
ISUG 113: File stream
Extreme performance - IDF UG
3 extreme performance - databases acceleration using ssd
4 extreme performance - part ii
2 extreme performance - smaller is better
1 extreme performance - part i
6 sql explorer - powershell dba

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Approach and Philosophy of On baking technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
sap open course for s4hana steps from ECC to s4
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Spectroscopy.pptx food analysis technology
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Approach and Philosophy of On baking technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Unlocking AI with Model Context Protocol (MCP)
Mobile App Security Testing_ A Comprehensive Guide.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
sap open course for s4hana steps from ECC to s4
“AI and Expert System Decision Support & Business Intelligence Systems”
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Spectroscopy.pptx food analysis technology

3 where are my keys - sql explore

  • 1. Where Are My Keys?Ami Levin | CTO | DBSophic LTD
  • 2. Session GoalsA revisit to some of the fundamental design principals of relational databases: Normalization rules, key selection, and the controversies associated with these issues from a very practical, hands-on perspective, with special emphasis on some surprising performance issues that may arise from sub-optimal selection of keys...
  • 4. Normalization“A relation whose domains are all simple can be represented in storage by a two-dimensional column homogeneous array of the kind discussed above. Some more complicated data structure is necessary for a relation with one or more non-simple domains. For this reason (and others to be cited below) the possibility of eliminating non-simple domains appears worth investigating. There is, in fact, a very simple elimination procedure, which we shall call…normalization”
  • 5. 1st Normal FormThere's no top-to-bottom or left-to-right ordering to the rows and columnsThere are no duplicate rowsEvery row-column intersection contains exactly one valueAll columns are regular
  • 7. 2nd Normal FormR is in 1st Normal Form (1NF).Given any candidate key K and any attribute A that is not a constituent of a candidate key, A depends upon the whole of K rather than just a part of it.
  • 9. 3rd Normal FormR is in second normal form (2NF)Every non-prime attribute of R is non-transitively dependent on every candidate key of R.A transitive dependency is a functional dependency, in which X -> Z (X determines Z) indirectly, by virtue of X -> Y and Y -> Z.
  • 11. KeysSimpleComposite Candidate Primary Artificial / Surrogate IntelligentNatural
  • 12. The DebateTo ID or not to ID?IDENTITY (1,1) PK vs. Natural key
  • 13. Pro ArtificialIn some cases, no natural key exists and an artificial key is the only option.Examples?
  • 14. Pro ArtificialNatural keys can change. Artificial keys never change.How Often?Cascading referential constraintsArtificial keys can change
  • 15. Pro ArtificialNatural keys may become very long and complex.Get longer with each level900 Bytes limit in SQL ServerMulti-column Joins
  • 16. Pro ArtificialArtificial keys improve performance. Simpler join predicatesEver increasing clustering effectShort keys = Smaller DB = Faster (?)
  • 17. Pro ArtificialArtificial keys reduce clustered index fragmentation. All types of artificial keys?Minimize maintenance down timeWhat about deletes?What about non-clustered indexes?
  • 18. Pro NaturalNatural keys have business meaning.Artificial keys are logically never queried for
  • 19. Pro NaturalQueries on tables using natural keys require fewer joins.The more familiar and meaningful the key, the less joins are required“Bypass” joins across levels
  • 20. Pro NaturalData consistency is maintained explicitly when using natural keys.Artificial keys enable logical duplicates
  • 21. Pro NaturalNatural keys eliminate potential physical clustering performance issues.Contention for clustered regions
  • 22. Less Mentioned IssuesArtificial keys are the de-facto standard.ORM generate artificial keysLINQ doesn’t cache composite key rows
  • 23. Less Mentioned IssuesData statistics and optimizations.Statistics on artificial keys are useless for parameter sniffingSelectivity estimations on composite key statistics are less accurate
  • 24. Less Mentioned IssuesModularity and portability.Migration to other platformsMerging with other databases
  • 26. Demo Design SpecURLCountry and city of ownerCountry ISO code needed by applicationData consistency is crucial
  • 28. Ask Yourself…Is there a natural key that I can use as PK? Are there a few natural candidates? Which one is the simplest and most familiar?How stable is it?How will it be used logically?What will be the table physical usage patterns?What are the common query types for this table?
  • 29. For More InformationA Relational Model of Data for Large Shared Data Banksby E. F. CODD.The Relational Model for Database Management: Version 2 by E.F. Codd. An introduction to database systemsby C.J Date. Database in Depth: Relational Theory for Practitionersby C.J Date.The Database Relational Model: A Retrospective Review and Analysisby C.J Date.Joe Celko's Data and Databases: Concepts in Practice by Joe Celko.Joe Celko's SQL for Smarties, Fourth Edition: Advanced SQL Programmingby Joe Celko.Database Modeling and Design, Fifth Edition: Logical Designby Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, and H.V. Jagadish.Pro SQL Server 2008 Relational Database Design and Implementationby Louis Davidson, Kevin Kline, Scott Klein, and Kurt Windisch.
  • 30. Where Are My Keys?Q&A