Where Are My (Primary) Keys? Ami Levin Mentor, Think Big. Move Fast.

Slides:



Advertisements
Similar presentations
CHAPTER OBJECTIVE: NORMALIZATION THE SNOWFLAKE SCHEMA.
Advertisements

The Relational Database Model
THE RELATIONAL DATABASE MODEL & THE DATABASE DEVELOPMENT PROCESS Fact of the Week: According to a Gartner study in ‘06, Microsoft SQL server had the highest.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 3-1 David M. Kroenke’s Chapter Three: The Relational Model and Normalization.
Fundamentals, Design, and Implementation, 9/e Chapter 4 The Relational Model and Normalization.
The Relational Database Model:
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
SLIDE 1IS 257 – Fall 2004 Database Design: Normalization and The Relational Model University of California, Berkeley School of Information.
Transforming Data Models into Database Designs
Chapter 3 The Relational Model and Normalization
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
RDBMS Concepts/ Session 3 / 1 of 22 Objectives  In this lesson, you will learn to:  Describe data redundancy  Describe the first, second, and third.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall, Modified by Dr. Mathis 3-1 David M. Kroenke’s Chapter Three: The Relational.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
1 5 Normalization. 2 5 Database Design Give some body of data to be represented in a database, how do we decide on a suitable logical structure for that.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Chapter 13 Designing Databases Systems Analysis and Design Kendall & Kendall Sixth Edition.
©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach.
A337 - Reed Smith1 Structure What is a database? –Table of information Rows are referred to as records Columns are referred to as fields Record identifier.
Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 4/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Chapter 4 Logical & Physical Database Design
Session id: Darrell Hilliard Senior Delivery Manager Oracle University Oracle Corporation.
Logical Database Design and the Relational Model.
Logical Database Design and Relation Data Model Muhammad Nasir
Normalization ACSC 425 Database Management Systems.
Databases Introduction - concepts. Concepts of Relational Databases.
Logical Database Design and Relational Data Model Muhammad Nasir
1 Agenda TMA02 M876 Block 4. 2 Model of database development data requirements conceptual data model logical schema schema and database establishing requirements.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Adapted from DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 3-1 Functional Dependencies and Normalization.
Logical Design & the Relational Model
SQL Server Statistics and its relationship with Query Optimizer
Understanding Data Storage
Database, tables and normal forms
Query Optimization Techniques
Revised: 2 April 2004 Fred Swartz
Chapter 4: Logical Database Design and the Relational Model
Normalization Karolina muszyńska
Chapter 5: Logical Database Design and the Relational Model
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Lecture 2 The Relational Model
Lecture # 13 (After 1st Exam)
Chapter 2: Intro to Relational Model
Translation of ER-diagram into Relational Schema
Chapter 9 Designing Databases
Normalization Referential Integrity
Relational Database.
Chapter 6 Normalization of Database Tables
Normalization By Jason Park Fall 2005 CS157A.
Normalization A337.
Database Processing: David M. Kroenke’s Chapter Three:
The Relational Model Textbook /7/2018.
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Normalization Normalization theory is based on the observation that relations with certain properties are more effective in inserting, updating and deleting.
Unit 7 Normalization (表格正規化).
Where Are My (Primary) Keys?
The Relational Database Model
Chapter 2: Intro to Relational Model
Copyright © 2018, 2015, 20 Pearson Education, Inc. All Rights Reserved Database Concepts Eighth Edition Chapter # 2 The Relational Model.
Relational Database Design
Database Design: Relational Model
Chapter 2: Intro to Relational Model
Execution plans Eugene
Chapter 17 Designing Databases
Chapter 4 The Relational Model and Normalization
Normalization By Jason Park Fall 2005 CS157A.
Database.
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Information system analysis and design
Presentation transcript:

Where Are My (Primary) Keys? Ami Levin Mentor, Think Big. Move Fast.

We Always Did it This Way… Where are my (primary) keys? 2 |

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... Where are my (primary) keys? 3 |

What is a Primary Key?

The Forefathers Where are my (primary) keys? 5 |

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 ” Where are my (primary) keys? 6 |

1 st 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 Where are my (primary) keys? 7 |

1 st Normal Form Where are my (primary) keys? 8 | SSN NamePhone Number Muammar Gaddafi Bashar Assad SSNFirst NameLast NamePhone Number MuammarGaddafi , BasharAssad SSNFirst NameLast NamePhone Number 1Phone Number MuammarGaddafi BasharAssad

2 nd 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. Where are my (primary) keys? 9 |

2 nd Normal Form Where are my (primary) keys? 10 | Order IDLine NumberCustomer 00011FISSA 00012FISSA 00021PARIS OrderDetailIDOrderIDLineNumberCustomer AC934245FF00B00011FISSA 8BA50CC2044AF00012FISSA F00B344923AB400021PARIS

3 rd 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. Where are my (primary) keys? 11 |

3 rd Normal Form Where are my (primary) keys? 12 | Order IDLine NumberProductManufacturer 00011ChairIKEA 00012GumMentos 00021Fighter JetBoeing

Keys  Simple  Composite  Candidate  Primary  Artificial / Surrogate  Intelligent  Natural Where are my (primary) keys? 13 |

The Debate To ID or not to ID?  IDENTITY (1,1) vs. Natural key Where are my (primary) keys? 14 |

Pro Artificial (I) In some cases, no natural key exists and an artificial key is the only option.  Examples? Where are my (primary) keys? 15 |

Pro Artificial (II) Natural keys can change. Artificial keys never change.  How Often?  Cascading referential constraints  Artificial keys can change Where are my (primary) keys? 16 |

Pro Artificial (III) Natural keys may be long and complex.  Become longer with each level  900 Bytes limit in SQL Server  Multi-column joins Where are my (primary) keys? 17 |

Pro Artificial (IX) Artificial keys help improve performance.  Simpler join predicates  Ever increasing clustering effect  Short keys = Smaller DB = Faster Where are my (primary) keys? 18 |

Pro Artificial (X) Artificial keys reduce clustered index fragmentation.  Minimize maintenance down time  What about deletes?  What about non-clustered indexes? Where are my (primary) keys? 19 |

Pro Natural (I) Natural keys have business meaning.  Artificial keys are never queried for Where are my (primary) keys? 20 |

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 Where are my (primary) keys? 21 |

Pro Natural (III) Data consistency is maintained explicitly when using natural keys.  Artificial keys enable logical duplicates Where are my (primary) keys? 22 |

Pro Natural (IX) Natural keys eliminate potential physical clustering performance issues.  Contention for clustered regions Where are my (primary) keys? 23 |

Less Mentioned Issues (I) Artificial keys are the de-facto standard.  ORMs generate artificial keys  LINQ doesn’t cache composite key rows …… Where are my (primary) keys? 24 |

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 Where are my (primary) keys? 25 |

Less Mentioned Issues (III) Modularity and portability.  Migration to other platforms  Merging with other databases Where are my (primary) keys? 26 |

Less Mentioned Issues (IX) Simplicity and aesthetics. Where are my (primary) keys? 27 |

Demo Spec A database of web sites.  URL  Country and city of owner  Country ISO code for external app  Data consistency is crucial Where are my (primary) keys? 28 |

Natural vs. Artificial Keys Where are my (primary) keys? 29 |

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? Where are my (primary) keys? 30 |

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) Where are my (primary) keys? 31 |

Where Are My Keys? Where are my (primary) keys? 32 |

Where Are My Keys? Where are my (primary) keys? 33 |