SlideShare a Scribd company logo
Richie Rump
    Jorriss LLC
      @Jorriss
www.jorriss.net
• Think of your database as your
  application foundation.
• The more time you spend on your
  foundation the better your application
  will be.
• If you get the foundation wrong you WILL
  have problems.
• Databases are highly complex systems.
• SQL Server has over twenty years of
  development.
• Learning SQL Server is like Alice’s rabbit
  hole. It keeps going down.
• Leverage your DBAs experience and
  knowledge of SQL Server.
When they do SELECT * because it’s easier
   than naming the fields they need
Source: http://dbareactions.tumblr.com/post/41716132853/when-they-do-
select-because-its-easier-than
When I see cursors written in new code

Source: http://dbareactions.tumblr.com/post/41643855887/when-i-see-cursors-
written-in-new-code
When the job applicant can’t code FizzBuzz
          during the interview
Source: http://dbareactions.tumblr.com/post/40938657699/when-the-job-
applicant-cant-code-fizzbuzz-during
•   Single Table
•   Wrong Types
•   No Indexes on Foreign Keys
•   Entity Attribute Value pattern
•   Guids
•   Surrogate Key / No Alternate Key
• All data is in one table
• Database Normalization is ignored.
• Redundant data everywhere
• Simple updates become complex
• Database changes become more
  frequent.
• Index strategy become messy
• Having the wrong data types can create
  long lasting issues.
• T-SQL can become challenging and
  inefficient.
• Understanding the differences between
  data types
• Better information, better decisions.
• CHAR
 – Fixed length. Value will be padded with spaces.
 – Size n bytes.
 – 1 – 8000 characters.
• VARCHAR
 – Variable length.
 – The storage size is the actual length of the data
   entered + 2 bytes.
 – 1 – 8000 characters.
• Holds UNICODE data.
• NCHAR
  – 1 – 4000 characters
  – Storage size twice n characters.
• NVARCHAR
  – 1 – 4000 character
  – Storage size twice n characters + 2 bytes.
• MAX allows a column size of 2GB.
• Cannot create an index on MAX columns
• REPEAT: Cannot create an index on MAX
  columns
• DATETIME
  – Accuracy rounded to .000, .003, or .007 second.
  – 8 Bytes
• DATETIME2 (n)
  – Accuracy to .0000001 second
  – 6 bytes for precisions less than 3;
  – 7 bytes for precisions 3 and 4.
  – All other precisions require 8 bytes.
• SMALLDATETIME
  – Accuracy to the minute.
  – No seconds
  – 4 bytes
• Demo
• BIGINT
  – -9,223,372,036,854,775,808 to
    9,223,372,036,854,775,807
  – Size 8 bytes
• INT
  – -2,147,483,648 to 2,147,483,647
  – Size 4 bytes
• SMALLINT
  – -32,768 to 32,767
  – Size 2 bytes
• TINYINT
  – 0 to 255
  – Size 1 bytes
• Size matters
• Put the extra time to size it correctly
• Don’t forget indexes store data on disk
• BIT
  – Values can be 0 or 1 (or NULL)
  – Size 1 byte
• TINYINT
  – Values can be 0 to 255
  – Size 1 byte
• Factor in your data access into your decision.
• May slow queries with JOINs
• Will have a performance impact on
  DELETEs
• Demo
Person
Entity ID          Name
1                  Cecil Phillip


Person_Attribute
Attribute ID   Entity ID           Attribute Type   Value
100            1                   Phone Number     305-555-9607
101            1                   Age              30
102            1                   Birthdate        2/9/1983
• No Data Type Enforcement
Person
Entity ID          Name
1                  Cecil Phillip


Person_Attribute
Attribute ID   Entity ID           Attribute Type   Value
100            1                   Phone Number     305-555-9607
101            1                   Age              501
102            1                   Birthdate        Yes I have one
• No NOT NULL Enforcement
Person
Entity ID          Name
1                  Cecil Phillip


Person_Attribute
Attribute ID   Entity ID           Attribute Type   Value
100            1                   Phone Number     NULL
101            1                   Age              30
102            1                   Birthdate        2/9/1983
• Querying much harder
• Demo…
• You would think this wouldn’t be a
  problem…
• Some benefits
  – Portable
  – Id can be generated from the app
  – That’s about it.
The problems:
• Size
  – Guids 16 bytes
  – Int 4 bytes
  – Disk and Memory
• Fragmentation
Source: http://blog.sqlauthority.com/2010/01/12/sql-server-
fragmentation-detect-fragmentation-and-eliminate-fragmentation/
A partial solution:
• NEWSEQUENTIALID()
  – Creates a sequential GUID.
  – Minimizes fragmentation
  – Still have the space issue.
• A surrogate key is a primary key
  automatically generated
• Surrogate keys are good thing.
• BUT when alternate key isn’t defined bad
  things can happen…bad things man, bad
  things.
• Demo…
• Data Model Resource Book vol 1-3
  Len Silverston
• Pro SQL Server 2012 Relational
  Database Design and Implementation
  Louis Davidson, Jessica Moss
Richie Rump
@Jorriss
http://jorriss.net
http://slideshare.net/jorriss
http://dotnetmiami.com

More Related Content

Similar to Database Design Disasters

03 AFCU - ITSM Seattle final
03 AFCU - ITSM Seattle final03 AFCU - ITSM Seattle final
03 AFCU - ITSM Seattle final
Jared Flanders
 
Blitzing with your defense bea con
Blitzing with your defense bea conBlitzing with your defense bea con
Blitzing with your defense bea con
Innismir
 
Dmk sb2010 web_defense
Dmk sb2010 web_defenseDmk sb2010 web_defense
Dmk sb2010 web_defense
Dan Kaminsky
 
OISC2013_Presentation
OISC2013_PresentationOISC2013_Presentation
OISC2013_Presentation
Austin Nagel
 

Similar to Database Design Disasters (20)

Black opspki 2
Black opspki 2Black opspki 2
Black opspki 2
 
Dama - Protecting Sensitive Data on a Database
Dama - Protecting Sensitive Data on a DatabaseDama - Protecting Sensitive Data on a Database
Dama - Protecting Sensitive Data on a Database
 
Osint
OsintOsint
Osint
 
03 AFCU - ITSM Seattle final
03 AFCU - ITSM Seattle final03 AFCU - ITSM Seattle final
03 AFCU - ITSM Seattle final
 
Fix What Matters: A Data Driven Approach to Vulnerability Management
Fix What Matters: A Data Driven Approach to Vulnerability ManagementFix What Matters: A Data Driven Approach to Vulnerability Management
Fix What Matters: A Data Driven Approach to Vulnerability Management
 
Blitzing with your defense bea con
Blitzing with your defense bea conBlitzing with your defense bea con
Blitzing with your defense bea con
 
Dmk sb2010 web_defense
Dmk sb2010 web_defenseDmk sb2010 web_defense
Dmk sb2010 web_defense
 
CISSP-Certified.pptx
CISSP-Certified.pptxCISSP-Certified.pptx
CISSP-Certified.pptx
 
Introduction to LavaPasswordFactory
Introduction to LavaPasswordFactoryIntroduction to LavaPasswordFactory
Introduction to LavaPasswordFactory
 
Personal Digital Security 101
Personal Digital Security 101Personal Digital Security 101
Personal Digital Security 101
 
Basic Security for Digital Companies - #MarketersUnbound (2014)
Basic Security for Digital Companies - #MarketersUnbound (2014)Basic Security for Digital Companies - #MarketersUnbound (2014)
Basic Security for Digital Companies - #MarketersUnbound (2014)
 
Passwords
PasswordsPasswords
Passwords
 
Network or perish
Network or perishNetwork or perish
Network or perish
 
Hunt for the red DA
Hunt for the red DAHunt for the red DA
Hunt for the red DA
 
OISC2013_Presentation
OISC2013_PresentationOISC2013_Presentation
OISC2013_Presentation
 
Protecting privacy with fuzzy-feeling test data
Protecting privacy with fuzzy-feeling test dataProtecting privacy with fuzzy-feeling test data
Protecting privacy with fuzzy-feeling test data
 
SOCs for the rest of us
SOCs for the rest of usSOCs for the rest of us
SOCs for the rest of us
 
Cyber Security
Cyber SecurityCyber Security
Cyber Security
 
Sitecore Symposium 2018 Theater Presentation - Shrink Your Workload, Grow You...
Sitecore Symposium 2018 Theater Presentation - Shrink Your Workload, Grow You...Sitecore Symposium 2018 Theater Presentation - Shrink Your Workload, Grow You...
Sitecore Symposium 2018 Theater Presentation - Shrink Your Workload, Grow You...
 
Neo4j Training Modeling
Neo4j Training ModelingNeo4j Training Modeling
Neo4j Training Modeling
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

Database Design Disasters

  • 1. Richie Rump Jorriss LLC @Jorriss www.jorriss.net
  • 2.
  • 3. • Think of your database as your application foundation. • The more time you spend on your foundation the better your application will be. • If you get the foundation wrong you WILL have problems.
  • 4. • Databases are highly complex systems. • SQL Server has over twenty years of development. • Learning SQL Server is like Alice’s rabbit hole. It keeps going down. • Leverage your DBAs experience and knowledge of SQL Server.
  • 5. When they do SELECT * because it’s easier than naming the fields they need Source: http://dbareactions.tumblr.com/post/41716132853/when-they-do- select-because-its-easier-than
  • 6. When I see cursors written in new code Source: http://dbareactions.tumblr.com/post/41643855887/when-i-see-cursors- written-in-new-code
  • 7. When the job applicant can’t code FizzBuzz during the interview Source: http://dbareactions.tumblr.com/post/40938657699/when-the-job- applicant-cant-code-fizzbuzz-during
  • 8. Single Table • Wrong Types • No Indexes on Foreign Keys • Entity Attribute Value pattern • Guids • Surrogate Key / No Alternate Key
  • 9. • All data is in one table • Database Normalization is ignored. • Redundant data everywhere • Simple updates become complex • Database changes become more frequent. • Index strategy become messy
  • 10.
  • 11. • Having the wrong data types can create long lasting issues. • T-SQL can become challenging and inefficient. • Understanding the differences between data types • Better information, better decisions.
  • 12. • CHAR – Fixed length. Value will be padded with spaces. – Size n bytes. – 1 – 8000 characters. • VARCHAR – Variable length. – The storage size is the actual length of the data entered + 2 bytes. – 1 – 8000 characters.
  • 13. • Holds UNICODE data. • NCHAR – 1 – 4000 characters – Storage size twice n characters. • NVARCHAR – 1 – 4000 character – Storage size twice n characters + 2 bytes.
  • 14. • MAX allows a column size of 2GB. • Cannot create an index on MAX columns • REPEAT: Cannot create an index on MAX columns
  • 15. • DATETIME – Accuracy rounded to .000, .003, or .007 second. – 8 Bytes • DATETIME2 (n) – Accuracy to .0000001 second – 6 bytes for precisions less than 3; – 7 bytes for precisions 3 and 4. – All other precisions require 8 bytes.
  • 16. • SMALLDATETIME – Accuracy to the minute. – No seconds – 4 bytes • Demo
  • 17. • BIGINT – -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 – Size 8 bytes • INT – -2,147,483,648 to 2,147,483,647 – Size 4 bytes
  • 18. • SMALLINT – -32,768 to 32,767 – Size 2 bytes • TINYINT – 0 to 255 – Size 1 bytes
  • 19. • Size matters • Put the extra time to size it correctly • Don’t forget indexes store data on disk
  • 20. • BIT – Values can be 0 or 1 (or NULL) – Size 1 byte • TINYINT – Values can be 0 to 255 – Size 1 byte • Factor in your data access into your decision.
  • 21. • May slow queries with JOINs • Will have a performance impact on DELETEs • Demo
  • 22.
  • 23.
  • 24. Person Entity ID Name 1 Cecil Phillip Person_Attribute Attribute ID Entity ID Attribute Type Value 100 1 Phone Number 305-555-9607 101 1 Age 30 102 1 Birthdate 2/9/1983
  • 25. • No Data Type Enforcement Person Entity ID Name 1 Cecil Phillip Person_Attribute Attribute ID Entity ID Attribute Type Value 100 1 Phone Number 305-555-9607 101 1 Age 501 102 1 Birthdate Yes I have one
  • 26. • No NOT NULL Enforcement Person Entity ID Name 1 Cecil Phillip Person_Attribute Attribute ID Entity ID Attribute Type Value 100 1 Phone Number NULL 101 1 Age 30 102 1 Birthdate 2/9/1983
  • 27. • Querying much harder • Demo…
  • 28. • You would think this wouldn’t be a problem… • Some benefits – Portable – Id can be generated from the app – That’s about it.
  • 29. The problems: • Size – Guids 16 bytes – Int 4 bytes – Disk and Memory • Fragmentation
  • 31.
  • 32. A partial solution: • NEWSEQUENTIALID() – Creates a sequential GUID. – Minimizes fragmentation – Still have the space issue.
  • 33. • A surrogate key is a primary key automatically generated • Surrogate keys are good thing. • BUT when alternate key isn’t defined bad things can happen…bad things man, bad things. • Demo…
  • 34. • Data Model Resource Book vol 1-3 Len Silverston • Pro SQL Server 2012 Relational Database Design and Implementation Louis Davidson, Jessica Moss