SlideShare a Scribd company logo
1 of 32
Where Are My (Primary) Keys?
Ami Levin
Mentor,
ALevin@SolidQ.com
Think Big. Move Fast.
Presented to the
San Francisco SQL Server User Group
September 2013
GEOData Database
The GEOData database that is used for the
demo can be downloaded here:
http://sdrv.ms/Z8ZmNb
Ami Levin – SolidQ2 |
Session Goals
Revisit one of the fundamental design
principals of relational databases - key
selection.
Explore the controversies associated with it
from a very practical, hands-on perspective,
with a special emphasis on some surprising
performance issues that may arise from sub-
optimal selection of keys...
Ami Levin – SolidQ3 |
What is a Primary Key?
Ami Levin – SolidQ
The Forefathers
Ami Levin – SolidQ5 |
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”
Ami Levin – SolidQ6 |
1st Normal Form
 There's no top-to-bottom or left-to-right
ordering to the rows and columns
 There are no duplicate rows
 Every row-column intersection contains
exactly one value
 There are no repeating groups
 All columns are regular
Ami Levin – SolidQ7 |
1st Normal Form
Ami Levin – SolidQ8 |
SSN Name PhoneNumber
123-45-6789 MuammarGaddafi +218-00-9876
987-65-4321 Bashar Assad +1-202-6543221
SSN First Name Last Name PhoneNumber
123-45-6789 Muammar Gaddafi
+218-00-9876,
+218-00-8765
987-65-4321 Bashar Assad +1-202-6543221
SSN First Name Last Name PhoneNumber1 PhoneNumber2
123-45-6789 Muammar Gaddafi +218-00-9876 +218-00-8765
987-65-4321 Bashar Assad +1-202-6543221
2nd Normal Form
 R is in 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.
Ami Levin – SolidQ9 |
2nd Normal Form
Ami Levin – SolidQ10 |
Order ID Line Number Customer
0001 1 FISSA
0001 2 FISSA
0002 1 PARIS
OrderDetailID OrderID LineNumber Customer
AC934245FF00B 0001 1 FISSA
8BA50CC2044AF 0001 2 FISSA
F00B344923AB4 0002 1 PARIS
3rd Normal Form
 R is in second normal form (2NF)
 Every non-prime attribute of R is non-transitively
dependent on every candidate key of R.
A non-prime attribute of R is an attribute that does not
belong to any 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.
Ami Levin – SolidQ11 |
3rd Normal Form
Ami Levin – SolidQ12 |
Order ID Line Number Product Manufacturer
0001 1 Chair IKEA
0001 2 Gum Mentos
0002 1 Fighter Jet Boeing
Keys
 Simple
 Composite
 Candidate
 Primary
 Artificial / Surrogate
 Intelligent
 Natural
Ami Levin – SolidQ13 |
The Debate
To ID or not to ID?
 IDENTITY (1,1) vs. Natural key
Ami Levin – SolidQ14 |
Pro Artificial (I)
In some cases, no natural key exists
and an artificial key is the only option.
 Examples?
Ami Levin – SolidQ15 |
Pro Artificial (II)
Natural keys can change.
Artificial keys never change.
 How Often?
 Cascading referential constraints
 Artificial keys can change
Ami Levin – SolidQ16 |
Pro Artificial (III)
Natural keys may be long and complex.
 Become longer with each level
 900 Bytes limit in SQL Server
 Multi-column joins
Ami Levin – SolidQ17 |
Pro Artificial (IX)
Artificial keys help improve
performance.
 Simpler join predicates
 Ever increasing clustering effect
 Short keys = Smaller DB = Faster
Ami Levin – SolidQ18 |
Pro Artificial (X)
Artificial keys reduce clustered index
fragmentation.
 Minimize maintenance down time
 What about deletes?
 What about non-clustered indexes?
Ami Levin – SolidQ19 |
Pro Natural (I)
Natural keys have business meaning.
 Artificial keys are never queried for
Ami Levin – SolidQ20 |
Pro Natural (II)
Queries on tables using natural keys
require fewer joins.
 The more familiar and meaningful the key,
the less joins are required
 “Bypass” joins
Ami Levin – SolidQ21 |
Pro Natural (III)
Data consistency is maintained
explicitly when using natural keys.
 Artificial keys enable logical duplicates
Ami Levin – SolidQ22 |
Pro Natural (IX)
Natural keys eliminate potential
physical clustering performance issues.
 Contention for clustered regions
Ami Levin – SolidQ23 |
Less Mentioned Issues (I)
Artificial keys are the de-facto standard.
 ORMs generate artificial keys
 LINQ doesn’t cache composite key rows
 …
Ami Levin – SolidQ24 |
Less Mentioned Issues (II)
Data statistics and optimizations.
 Statistics on artificial keys are useless for
parameter sniffing
 Estimations on composite key statistics
are less accurate
Ami Levin – SolidQ25 |
Less Mentioned Issues (III)
Modularity and portability.
 Migration to other platforms
 Merging with other databases
Ami Levin – SolidQ26 |
Less Mentioned Issues (IX)
Simplicity and aesthetics.
Ami Levin – SolidQ27 |
Demo Spec
A database of web sites.
 URL
 Country and city of owner
 Country ISO code for external app
 Data consistency is crucial
Ami Levin – SolidQ28 |
Natural vs. Artificial Keys
Ami Levin – SolidQ29 |
Ask Yourself
 Is there a natural key that I can use as a primary
key?
 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 physical access patterns for this
table?
 What are the common query types for this table?
Ami Levin – SolidQ30 |
For More Information
 A Relational Model of Data for Large Shared Data Banks (E.F.
CODD)
 The Relational Model for Database Management: Version 2 (E.F.
Codd)
 An introduction to database systems (C.J. Date)
 Database in Depth: Relational Theory for Practitioners (C.J.
Date)
 The Database Relational Model: A Retrospective Review and
Analysis (C.J. Date)
 Joe Celko's Data and Databases: Concepts in Practice (J. Celko)
 Joe Celko's SQL for Smarties, Fourth Edition: Advanced SQL
Programming (J. Celko)
 Database Modeling and Design, Fifth Edition: Logical Design
(T.J. Teorey, S.S. Lightstone, T. Nadeau, and H.V. Jagadish)
 Pro SQL Server 2008 Relational Database Design and
Implementation (L. Davidson, K. Kline, S. Klein, and K. Windisch)
Ami Levin – SolidQ31 |
WhereAre My Keys?
Ami Levin – SolidQ32 |

More Related Content

Similar to Microsoft SQL Server Relational Databases and Primary Keys

JavaBeer_Clean architecture_update.v2.pptx
JavaBeer_Clean architecture_update.v2.pptxJavaBeer_Clean architecture_update.v2.pptx
JavaBeer_Clean architecture_update.v2.pptxssuser78ac77
 
The little engine(s) that could: scaling online social networks
The little engine(s) that could: scaling online social  networksThe little engine(s) that could: scaling online social  networks
The little engine(s) that could: scaling online social networksJosep M. Pujol
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework OverviewEric Nelson
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2Eric Nelson
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity FrameworkDoncho Minkov
 
Ni2 Positioning Overview May 2006
Ni2 Positioning Overview  May 2006Ni2 Positioning Overview  May 2006
Ni2 Positioning Overview May 2006kvz
 
Intelligent query converter a domain independent interfacefor conversion
Intelligent query converter a domain independent interfacefor conversionIntelligent query converter a domain independent interfacefor conversion
Intelligent query converter a domain independent interfacefor conversionIAEME Publication
 
My 2019 SQL Saturday In San Diego presentation
My 2019 SQL Saturday In San Diego presentationMy 2019 SQL Saturday In San Diego presentation
My 2019 SQL Saturday In San Diego presentationSteve Rezhener, MBA
 
Database Performance
Database PerformanceDatabase Performance
Database PerformanceBoris Hristov
 
CIKB - Software Architecture Analysis Design
CIKB - Software Architecture Analysis DesignCIKB - Software Architecture Analysis Design
CIKB - Software Architecture Analysis DesignAntonio Castellon
 
Sstc benton bovee 2933a 2012 04-26
Sstc benton bovee 2933a 2012 04-26Sstc benton bovee 2933a 2012 04-26
Sstc benton bovee 2933a 2012 04-26Benton "Ben" Bovée
 
DoDAF Overview Using Innoslate Webinar
DoDAF Overview Using Innoslate WebinarDoDAF Overview Using Innoslate Webinar
DoDAF Overview Using Innoslate WebinarElizabeth Steiner
 
SMU MSCIT Sem 1 Winter 2014 Assignments
SMU MSCIT Sem 1 Winter 2014 AssignmentsSMU MSCIT Sem 1 Winter 2014 Assignments
SMU MSCIT Sem 1 Winter 2014 Assignmentssolved_assignments
 
Server FarmIP PhoneEnd-usersCorporate Computers.docx
Server FarmIP PhoneEnd-usersCorporate Computers.docxServer FarmIP PhoneEnd-usersCorporate Computers.docx
Server FarmIP PhoneEnd-usersCorporate Computers.docxklinda1
 
Structured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and DesignStructured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and DesignMotaz Saad
 

Similar to Microsoft SQL Server Relational Databases and Primary Keys (20)

JavaBeer_Clean architecture_update.v2.pptx
JavaBeer_Clean architecture_update.v2.pptxJavaBeer_Clean architecture_update.v2.pptx
JavaBeer_Clean architecture_update.v2.pptx
 
The little engine(s) that could: scaling online social networks
The little engine(s) that could: scaling online social  networksThe little engine(s) that could: scaling online social  networks
The little engine(s) that could: scaling online social networks
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
Database part2-
Database part2-Database part2-
Database part2-
 
NoSQL
NoSQLNoSQL
NoSQL
 
Ni2 Positioning Overview May 2006
Ni2 Positioning Overview  May 2006Ni2 Positioning Overview  May 2006
Ni2 Positioning Overview May 2006
 
Rdbms
RdbmsRdbms
Rdbms
 
Intelligent query converter a domain independent interfacefor conversion
Intelligent query converter a domain independent interfacefor conversionIntelligent query converter a domain independent interfacefor conversion
Intelligent query converter a domain independent interfacefor conversion
 
My 2019 SQL Saturday In San Diego presentation
My 2019 SQL Saturday In San Diego presentationMy 2019 SQL Saturday In San Diego presentation
My 2019 SQL Saturday In San Diego presentation
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
CIKB - Software Architecture Analysis Design
CIKB - Software Architecture Analysis DesignCIKB - Software Architecture Analysis Design
CIKB - Software Architecture Analysis Design
 
Sstc benton bovee 2933a 2012 04-26
Sstc benton bovee 2933a 2012 04-26Sstc benton bovee 2933a 2012 04-26
Sstc benton bovee 2933a 2012 04-26
 
Bt0066
Bt0066Bt0066
Bt0066
 
B T0066
B T0066B T0066
B T0066
 
DoDAF Overview Using Innoslate Webinar
DoDAF Overview Using Innoslate WebinarDoDAF Overview Using Innoslate Webinar
DoDAF Overview Using Innoslate Webinar
 
SMU MSCIT Sem 1 Winter 2014 Assignments
SMU MSCIT Sem 1 Winter 2014 AssignmentsSMU MSCIT Sem 1 Winter 2014 Assignments
SMU MSCIT Sem 1 Winter 2014 Assignments
 
Server FarmIP PhoneEnd-usersCorporate Computers.docx
Server FarmIP PhoneEnd-usersCorporate Computers.docxServer FarmIP PhoneEnd-usersCorporate Computers.docx
Server FarmIP PhoneEnd-usersCorporate Computers.docx
 
Structured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and DesignStructured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and Design
 

More from Mark Ginnebaugh

Automating Microsoft Power BI Creations 2015
Automating Microsoft Power BI Creations 2015Automating Microsoft Power BI Creations 2015
Automating Microsoft Power BI Creations 2015Mark Ginnebaugh
 
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction Mark Ginnebaugh
 
Platfora - An Analytics Sandbox In A World Of Big Data
Platfora - An Analytics Sandbox In A World Of Big DataPlatfora - An Analytics Sandbox In A World Of Big Data
Platfora - An Analytics Sandbox In A World Of Big DataMark Ginnebaugh
 
DesignMind Microsoft Business Intelligence SQL Server
DesignMind Microsoft Business Intelligence SQL ServerDesignMind Microsoft Business Intelligence SQL Server
DesignMind Microsoft Business Intelligence SQL ServerMark Ginnebaugh
 
San Francisco Bay Area SQL Server July 2013 meetings
San Francisco Bay Area SQL Server July 2013 meetingsSan Francisco Bay Area SQL Server July 2013 meetings
San Francisco Bay Area SQL Server July 2013 meetingsMark Ginnebaugh
 
Silicon Valley SQL Server User Group June 2013
Silicon Valley SQL Server User Group June 2013Silicon Valley SQL Server User Group June 2013
Silicon Valley SQL Server User Group June 2013Mark Ginnebaugh
 
Microsoft SQL Server Continuous Integration
Microsoft SQL Server Continuous IntegrationMicrosoft SQL Server Continuous Integration
Microsoft SQL Server Continuous IntegrationMark Ginnebaugh
 
Hortonworks Big Data & Hadoop
Hortonworks Big Data & HadoopHortonworks Big Data & Hadoop
Hortonworks Big Data & HadoopMark Ginnebaugh
 
Microsoft SQL Server Physical Join Operators
Microsoft SQL Server Physical Join OperatorsMicrosoft SQL Server Physical Join Operators
Microsoft SQL Server Physical Join OperatorsMark Ginnebaugh
 
Microsoft PowerPivot & Power View in Excel 2013
Microsoft PowerPivot & Power View in Excel 2013Microsoft PowerPivot & Power View in Excel 2013
Microsoft PowerPivot & Power View in Excel 2013Mark Ginnebaugh
 
Microsoft Data Warehouse Business Intelligence Lifecycle - The Kimball Approach
Microsoft Data Warehouse Business Intelligence Lifecycle - The Kimball ApproachMicrosoft Data Warehouse Business Intelligence Lifecycle - The Kimball Approach
Microsoft Data Warehouse Business Intelligence Lifecycle - The Kimball ApproachMark Ginnebaugh
 
Fusion-io Memory Flash for Microsoft SQL Server 2012
Fusion-io Memory Flash for Microsoft SQL Server 2012Fusion-io Memory Flash for Microsoft SQL Server 2012
Fusion-io Memory Flash for Microsoft SQL Server 2012Mark Ginnebaugh
 
Microsoft Data Mining 2012
Microsoft Data Mining 2012Microsoft Data Mining 2012
Microsoft Data Mining 2012Mark Ginnebaugh
 
Microsoft SQL Server PASS News August 2012
Microsoft SQL Server PASS News August 2012Microsoft SQL Server PASS News August 2012
Microsoft SQL Server PASS News August 2012Mark Ginnebaugh
 
Business Intelligence Dashboard Design Best Practices
Business Intelligence Dashboard Design Best PracticesBusiness Intelligence Dashboard Design Best Practices
Business Intelligence Dashboard Design Best PracticesMark Ginnebaugh
 
Microsoft Mobile Business Intelligence
Microsoft Mobile Business Intelligence Microsoft Mobile Business Intelligence
Microsoft Mobile Business Intelligence Mark Ginnebaugh
 
Microsoft SQL Server 2012 Cloud Ready
Microsoft SQL Server 2012 Cloud ReadyMicrosoft SQL Server 2012 Cloud Ready
Microsoft SQL Server 2012 Cloud ReadyMark Ginnebaugh
 
Microsoft SQL Server 2012 Master Data Services
Microsoft SQL Server 2012 Master Data ServicesMicrosoft SQL Server 2012 Master Data Services
Microsoft SQL Server 2012 Master Data ServicesMark Ginnebaugh
 
Microsoft SQL Server PowerPivot
Microsoft SQL Server PowerPivotMicrosoft SQL Server PowerPivot
Microsoft SQL Server PowerPivotMark Ginnebaugh
 
Microsoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMicrosoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMark Ginnebaugh
 

More from Mark Ginnebaugh (20)

Automating Microsoft Power BI Creations 2015
Automating Microsoft Power BI Creations 2015Automating Microsoft Power BI Creations 2015
Automating Microsoft Power BI Creations 2015
 
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
 
Platfora - An Analytics Sandbox In A World Of Big Data
Platfora - An Analytics Sandbox In A World Of Big DataPlatfora - An Analytics Sandbox In A World Of Big Data
Platfora - An Analytics Sandbox In A World Of Big Data
 
DesignMind Microsoft Business Intelligence SQL Server
DesignMind Microsoft Business Intelligence SQL ServerDesignMind Microsoft Business Intelligence SQL Server
DesignMind Microsoft Business Intelligence SQL Server
 
San Francisco Bay Area SQL Server July 2013 meetings
San Francisco Bay Area SQL Server July 2013 meetingsSan Francisco Bay Area SQL Server July 2013 meetings
San Francisco Bay Area SQL Server July 2013 meetings
 
Silicon Valley SQL Server User Group June 2013
Silicon Valley SQL Server User Group June 2013Silicon Valley SQL Server User Group June 2013
Silicon Valley SQL Server User Group June 2013
 
Microsoft SQL Server Continuous Integration
Microsoft SQL Server Continuous IntegrationMicrosoft SQL Server Continuous Integration
Microsoft SQL Server Continuous Integration
 
Hortonworks Big Data & Hadoop
Hortonworks Big Data & HadoopHortonworks Big Data & Hadoop
Hortonworks Big Data & Hadoop
 
Microsoft SQL Server Physical Join Operators
Microsoft SQL Server Physical Join OperatorsMicrosoft SQL Server Physical Join Operators
Microsoft SQL Server Physical Join Operators
 
Microsoft PowerPivot & Power View in Excel 2013
Microsoft PowerPivot & Power View in Excel 2013Microsoft PowerPivot & Power View in Excel 2013
Microsoft PowerPivot & Power View in Excel 2013
 
Microsoft Data Warehouse Business Intelligence Lifecycle - The Kimball Approach
Microsoft Data Warehouse Business Intelligence Lifecycle - The Kimball ApproachMicrosoft Data Warehouse Business Intelligence Lifecycle - The Kimball Approach
Microsoft Data Warehouse Business Intelligence Lifecycle - The Kimball Approach
 
Fusion-io Memory Flash for Microsoft SQL Server 2012
Fusion-io Memory Flash for Microsoft SQL Server 2012Fusion-io Memory Flash for Microsoft SQL Server 2012
Fusion-io Memory Flash for Microsoft SQL Server 2012
 
Microsoft Data Mining 2012
Microsoft Data Mining 2012Microsoft Data Mining 2012
Microsoft Data Mining 2012
 
Microsoft SQL Server PASS News August 2012
Microsoft SQL Server PASS News August 2012Microsoft SQL Server PASS News August 2012
Microsoft SQL Server PASS News August 2012
 
Business Intelligence Dashboard Design Best Practices
Business Intelligence Dashboard Design Best PracticesBusiness Intelligence Dashboard Design Best Practices
Business Intelligence Dashboard Design Best Practices
 
Microsoft Mobile Business Intelligence
Microsoft Mobile Business Intelligence Microsoft Mobile Business Intelligence
Microsoft Mobile Business Intelligence
 
Microsoft SQL Server 2012 Cloud Ready
Microsoft SQL Server 2012 Cloud ReadyMicrosoft SQL Server 2012 Cloud Ready
Microsoft SQL Server 2012 Cloud Ready
 
Microsoft SQL Server 2012 Master Data Services
Microsoft SQL Server 2012 Master Data ServicesMicrosoft SQL Server 2012 Master Data Services
Microsoft SQL Server 2012 Master Data Services
 
Microsoft SQL Server PowerPivot
Microsoft SQL Server PowerPivotMicrosoft SQL Server PowerPivot
Microsoft SQL Server PowerPivot
 
Microsoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMicrosoft SQL Server Testing Frameworks
Microsoft SQL Server Testing Frameworks
 

Recently uploaded

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Microsoft SQL Server Relational Databases and Primary Keys

  • 1. Where Are My (Primary) Keys? Ami Levin Mentor, ALevin@SolidQ.com Think Big. Move Fast. Presented to the San Francisco SQL Server User Group September 2013
  • 2. GEOData Database The GEOData database that is used for the demo can be downloaded here: http://sdrv.ms/Z8ZmNb Ami Levin – SolidQ2 |
  • 3. Session Goals Revisit one of the fundamental design principals of relational databases - key selection. Explore the controversies associated with it from a very practical, hands-on perspective, with a special emphasis on some surprising performance issues that may arise from sub- optimal selection of keys... Ami Levin – SolidQ3 |
  • 4. What is a Primary Key? Ami Levin – SolidQ
  • 6. 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” Ami Levin – SolidQ6 |
  • 7. 1st Normal Form  There's no top-to-bottom or left-to-right ordering to the rows and columns  There are no duplicate rows  Every row-column intersection contains exactly one value  There are no repeating groups  All columns are regular Ami Levin – SolidQ7 |
  • 8. 1st Normal Form Ami Levin – SolidQ8 | SSN Name PhoneNumber 123-45-6789 MuammarGaddafi +218-00-9876 987-65-4321 Bashar Assad +1-202-6543221 SSN First Name Last Name PhoneNumber 123-45-6789 Muammar Gaddafi +218-00-9876, +218-00-8765 987-65-4321 Bashar Assad +1-202-6543221 SSN First Name Last Name PhoneNumber1 PhoneNumber2 123-45-6789 Muammar Gaddafi +218-00-9876 +218-00-8765 987-65-4321 Bashar Assad +1-202-6543221
  • 9. 2nd Normal Form  R is in 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. Ami Levin – SolidQ9 |
  • 10. 2nd Normal Form Ami Levin – SolidQ10 | Order ID Line Number Customer 0001 1 FISSA 0001 2 FISSA 0002 1 PARIS OrderDetailID OrderID LineNumber Customer AC934245FF00B 0001 1 FISSA 8BA50CC2044AF 0001 2 FISSA F00B344923AB4 0002 1 PARIS
  • 11. 3rd Normal Form  R is in second normal form (2NF)  Every non-prime attribute of R is non-transitively dependent on every candidate key of R. A non-prime attribute of R is an attribute that does not belong to any 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. Ami Levin – SolidQ11 |
  • 12. 3rd Normal Form Ami Levin – SolidQ12 | Order ID Line Number Product Manufacturer 0001 1 Chair IKEA 0001 2 Gum Mentos 0002 1 Fighter Jet Boeing
  • 13. Keys  Simple  Composite  Candidate  Primary  Artificial / Surrogate  Intelligent  Natural Ami Levin – SolidQ13 |
  • 14. The Debate To ID or not to ID?  IDENTITY (1,1) vs. Natural key Ami Levin – SolidQ14 |
  • 15. Pro Artificial (I) In some cases, no natural key exists and an artificial key is the only option.  Examples? Ami Levin – SolidQ15 |
  • 16. Pro Artificial (II) Natural keys can change. Artificial keys never change.  How Often?  Cascading referential constraints  Artificial keys can change Ami Levin – SolidQ16 |
  • 17. Pro Artificial (III) Natural keys may be long and complex.  Become longer with each level  900 Bytes limit in SQL Server  Multi-column joins Ami Levin – SolidQ17 |
  • 18. Pro Artificial (IX) Artificial keys help improve performance.  Simpler join predicates  Ever increasing clustering effect  Short keys = Smaller DB = Faster Ami Levin – SolidQ18 |
  • 19. Pro Artificial (X) Artificial keys reduce clustered index fragmentation.  Minimize maintenance down time  What about deletes?  What about non-clustered indexes? Ami Levin – SolidQ19 |
  • 20. Pro Natural (I) Natural keys have business meaning.  Artificial keys are never queried for Ami Levin – SolidQ20 |
  • 21. Pro Natural (II) Queries on tables using natural keys require fewer joins.  The more familiar and meaningful the key, the less joins are required  “Bypass” joins Ami Levin – SolidQ21 |
  • 22. Pro Natural (III) Data consistency is maintained explicitly when using natural keys.  Artificial keys enable logical duplicates Ami Levin – SolidQ22 |
  • 23. Pro Natural (IX) Natural keys eliminate potential physical clustering performance issues.  Contention for clustered regions Ami Levin – SolidQ23 |
  • 24. Less Mentioned Issues (I) Artificial keys are the de-facto standard.  ORMs generate artificial keys  LINQ doesn’t cache composite key rows  … Ami Levin – SolidQ24 |
  • 25. Less Mentioned Issues (II) Data statistics and optimizations.  Statistics on artificial keys are useless for parameter sniffing  Estimations on composite key statistics are less accurate Ami Levin – SolidQ25 |
  • 26. Less Mentioned Issues (III) Modularity and portability.  Migration to other platforms  Merging with other databases Ami Levin – SolidQ26 |
  • 27. Less Mentioned Issues (IX) Simplicity and aesthetics. Ami Levin – SolidQ27 |
  • 28. Demo Spec A database of web sites.  URL  Country and city of owner  Country ISO code for external app  Data consistency is crucial Ami Levin – SolidQ28 |
  • 29. Natural vs. Artificial Keys Ami Levin – SolidQ29 |
  • 30. Ask Yourself  Is there a natural key that I can use as a primary key?  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 physical access patterns for this table?  What are the common query types for this table? Ami Levin – SolidQ30 |
  • 31. For More Information  A Relational Model of Data for Large Shared Data Banks (E.F. CODD)  The Relational Model for Database Management: Version 2 (E.F. Codd)  An introduction to database systems (C.J. Date)  Database in Depth: Relational Theory for Practitioners (C.J. Date)  The Database Relational Model: A Retrospective Review and Analysis (C.J. Date)  Joe Celko's Data and Databases: Concepts in Practice (J. Celko)  Joe Celko's SQL for Smarties, Fourth Edition: Advanced SQL Programming (J. Celko)  Database Modeling and Design, Fifth Edition: Logical Design (T.J. Teorey, S.S. Lightstone, T. Nadeau, and H.V. Jagadish)  Pro SQL Server 2008 Relational Database Design and Implementation (L. Davidson, K. Kline, S. Klein, and K. Windisch) Ami Levin – SolidQ31 |
  • 32. WhereAre My Keys? Ami Levin – SolidQ32 |