Elegant & Efficient Database Design	Tim Allen		Becky Sweger
Elegant and Efficient Database Design
	Naming ConventionsJoshua
Jana
John-David
Jill
Jessa
Jinger
Josiah
Joy-Anna
Jedidiah
Jeremiah
Jason
James
Justin
Jackson
Johannah
Jennifer	Naming ConventionsPick one and enforce it: camelCase, PascalCase, under_scoresWhy?Cleaner codeLogical joinsSanity of future developers and future youExplicitly name constraintsAvoid keywords as column namesWRDS Fail: group, client, school, subscriber, and institution are all used for the same data entity
	DB Normalization
	DB NormalizationThe key, the whole key, and nothing but the key.  So help me Codd.
	DB Normalizationhttp://en.wikipedia.org/wiki/File:Insertion_anomaly.svg
	Why normalize?Avoid data duplicationLet end users make their own changesAvoid data anomaliesThird-party tools rely on normalized data
	IndexingFind a book in Van Pelt without a card catalog…
	Indexing: Data Pages
	Indexing: Clustered B-TreeIndexes in SQL Server are organized as B-treesmember name clustered index  (image from Clustered Indexes vs. Nonclustered Indexes in SQL Server:http://tr.im/AeU5)
	Indexing: Non-Clustered B-Treemember id non-clustered index  (image from Clustered Indexes vs. Nonclustered Indexes in SQL Server:http://tr.im/AeU5)
	Indexing: Other TypesUniqueFull-textIncluded columnsIndexed viewsXMLFiltered (new for 2008)Spatial (new for 2008)http://msdn.microsoft.com/en-us/library/ms175049.aspx
	Indexing: Primary KeysPrimary key = unique index (clustered or non-clustered)
	Indexing considerations: tablesClustered index on every tablemember name non-clustered index  (image from Clustered Indexes vs. Nonclustered Indexes in SQL Server:http://tr.im/AeU5)
	Indexing considerations: tablesInteger primary key on every table/* take checkpoint, clear buffers & cache */SELECT s.term, s.section_id, COUNT(penn_id)FROM flat_section s JOIN flat_enrollment eON s.section_id = e.section_idAND s.term = e.termGROUP BY s.term, s.section_id
	Indexing considerations: tablesResults
       Indexing considerations: columns
       Indexing considerations: columnsColumns you join on: indexed integers are your friend!How are the columns used in queries?Cardinality: 1:1, 1:many, many:manyData typeIndexing multiple columns: moderationGoal 1: performance!Goal 2: smallest index file possible.
       Indexing Considerations: Yes! No!
       Indexing Considerations: Yes! No!TINY: 8 bits (0 – 255): 01010101SMALL INTEGER: 16 bits (0 – 65536): 0101010101010101INTEGER: 32 bits (0 – 16777215): 01010101010101010101010101010101VARCHAR ‘philadelphia’: 104 bits, at least (encoding UTF-8):  01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101Consider joining 4 tables on ‘philadelphia’: 4 initial lookups on indexes, 8 times as bulky and less cacheable as a small integer.Index on VARCHARs only when neededKeeps index files smaller and less chance of fragmentation; fragmented index files make Matt Frew’s life hellish (no, that is NOT a positive!)Consider purpose: don’t index for a one time script or report

More Related Content

PDF
iNaturalist.org: Document Analysis
PPTX
Comparison of MPP Data Warehouse Platforms
DOCX
Sample job motivation letter
PPTX
SQL Server 2012 Best Practices
PPTX
SQL Server 2008 Development for Programmers
PPTX
Query Optimization in SQL Server
PDF
Speed up sql
PPT
Indexing Strategies
iNaturalist.org: Document Analysis
Comparison of MPP Data Warehouse Platforms
Sample job motivation letter
SQL Server 2012 Best Practices
SQL Server 2008 Development for Programmers
Query Optimization in SQL Server
Speed up sql
Indexing Strategies

Similar to Elegant and Efficient Database Design (20)

PPTX
Performance By Design
PDF
Building better SQL Server Databases
PPTX
Ms sql server tips 1 0
PPTX
Sql server ___________session_17(indexes)
PPTX
Database Performance Tuning
PPTX
SQL Server - Introduction to TSQL
PPTX
Sql good practices
PPTX
Database design best practices
PDF
SQL Database Performance Tuning for Developers
PPTX
Index the obvious and not so obvious
PPTX
02 database oprimization - improving sql performance - ent-db
PPTX
presentation is on database for sql and stored procedures
PDF
Tips for Database Performance
PDF
SQL Joins and Query Optimization
PPTX
Sql performance tuning
PDF
MySQL INDEXES
PPT
15 protips for mysql users pfz
PDF
Query Tuning for Database Pros & Developers
PDF
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
PPT
Indexing
Performance By Design
Building better SQL Server Databases
Ms sql server tips 1 0
Sql server ___________session_17(indexes)
Database Performance Tuning
SQL Server - Introduction to TSQL
Sql good practices
Database design best practices
SQL Database Performance Tuning for Developers
Index the obvious and not so obvious
02 database oprimization - improving sql performance - ent-db
presentation is on database for sql and stored procedures
Tips for Database Performance
SQL Joins and Query Optimization
Sql performance tuning
MySQL INDEXES
15 protips for mysql users pfz
Query Tuning for Database Pros & Developers
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Indexing
Ad

Recently uploaded (20)

PDF
Examining Bias in AI Generated News Content.pdf
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
SaaS reusability assessment using machine learning techniques
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
Connector Corner: Transform Unstructured Documents with Agentic Automation
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
PPTX
Information-Technology-in-Human-Society.pptx
PDF
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
PDF
NewMind AI Journal Monthly Chronicles - August 2025
PDF
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PPTX
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PPTX
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
Examining Bias in AI Generated News Content.pdf
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
SaaS reusability assessment using machine learning techniques
NewMind AI Weekly Chronicles – August ’25 Week IV
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Connector Corner: Transform Unstructured Documents with Agentic Automation
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Data Virtualization in Action: Scaling APIs and Apps with FME
Introduction to MCP and A2A Protocols: Enabling Agent Communication
Information-Technology-in-Human-Society.pptx
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
NewMind AI Journal Monthly Chronicles - August 2025
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
giants, standing on the shoulders of - by Daniel Stenberg
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
Early detection and classification of bone marrow changes in lumbar vertebrae...
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
Rapid Prototyping: A lecture on prototyping techniques for interface design
Ad

Elegant and Efficient Database Design

  • 1. Elegant & Efficient Database Design Tim Allen Becky Sweger
  • 13. Jason
  • 14. James
  • 18. Jennifer Naming ConventionsPick one and enforce it: camelCase, PascalCase, under_scoresWhy?Cleaner codeLogical joinsSanity of future developers and future youExplicitly name constraintsAvoid keywords as column namesWRDS Fail: group, client, school, subscriber, and institution are all used for the same data entity
  • 20. DB NormalizationThe key, the whole key, and nothing but the key. So help me Codd.
  • 22. Why normalize?Avoid data duplicationLet end users make their own changesAvoid data anomaliesThird-party tools rely on normalized data
  • 23. IndexingFind a book in Van Pelt without a card catalog…
  • 25. Indexing: Clustered B-TreeIndexes in SQL Server are organized as B-treesmember name clustered index (image from Clustered Indexes vs. Nonclustered Indexes in SQL Server:http://tr.im/AeU5)
  • 26. Indexing: Non-Clustered B-Treemember id non-clustered index (image from Clustered Indexes vs. Nonclustered Indexes in SQL Server:http://tr.im/AeU5)
  • 27. Indexing: Other TypesUniqueFull-textIncluded columnsIndexed viewsXMLFiltered (new for 2008)Spatial (new for 2008)http://msdn.microsoft.com/en-us/library/ms175049.aspx
  • 28. Indexing: Primary KeysPrimary key = unique index (clustered or non-clustered)
  • 29. Indexing considerations: tablesClustered index on every tablemember name non-clustered index (image from Clustered Indexes vs. Nonclustered Indexes in SQL Server:http://tr.im/AeU5)
  • 30. Indexing considerations: tablesInteger primary key on every table/* take checkpoint, clear buffers & cache */SELECT s.term, s.section_id, COUNT(penn_id)FROM flat_section s JOIN flat_enrollment eON s.section_id = e.section_idAND s.term = e.termGROUP BY s.term, s.section_id
  • 32. Indexing considerations: columns
  • 33. Indexing considerations: columnsColumns you join on: indexed integers are your friend!How are the columns used in queries?Cardinality: 1:1, 1:many, many:manyData typeIndexing multiple columns: moderationGoal 1: performance!Goal 2: smallest index file possible.
  • 34. Indexing Considerations: Yes! No!
  • 35. Indexing Considerations: Yes! No!TINY: 8 bits (0 – 255): 01010101SMALL INTEGER: 16 bits (0 – 65536): 0101010101010101INTEGER: 32 bits (0 – 16777215): 01010101010101010101010101010101VARCHAR ‘philadelphia’: 104 bits, at least (encoding UTF-8): 01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101Consider joining 4 tables on ‘philadelphia’: 4 initial lookups on indexes, 8 times as bulky and less cacheable as a small integer.Index on VARCHARs only when neededKeeps index files smaller and less chance of fragmentation; fragmented index files make Matt Frew’s life hellish (no, that is NOT a positive!)Consider purpose: don’t index for a one time script or report
  • 36. Indexing Example: WRDS Queries
  • 37. Indexing Example: WRDS QueriesLarge table: millions of rowsA record for each WRDS queryVARCHAR columns that should be INTEGERSReport requests for subscribers asking number of queries for a date range group by library and fileBefore indexing, full table scan: 30 secs per queryIndex added: subscriber, query date, library, fileAfter indexing, without table scan: 0.02 secs per query
  • 38. Indexing Tools: SSMSFrom the Query menu:SET STATISTICS TIME, SET STATISTICS IOInclude Actual Execution Plan
  • 39. Indexing Tools: DMVDynamic Management Views & Functions: http://msdn.microsoft.com/en-us/magazine/cc135978.aspx
  • 40. Indexing Tools: Tuning AdvisorAnalyzes workloads
  • 42. Best Practices: Data TypesDon’t skimp on column length: Yes/No? Maybe. Open/Closed? Under construction. Black/White? Grey.Know required level of precision, and leave yourself room to grow.Accuracy to the day, minute, millisecond?
  • 43. Best Practices: DeletionLogical deletes vs. physical deletes
  • 44. Best Practices: work the DBForeign KeysUnique indexesCheck constraintsDefault constraintsTriggersimage courtesy of My New Filing Technique is Unstoppable by David Rees: http://www.mnftiu.cc/2002/11/26/filing-009/ (nsfw)
  • 46. Best Practices: Crunch Time!“Temporary” projectsBalance between today’s pragmatism and tomorrow’s painCode review sooner
  • 47. Best Practices: ExperimentExperiment in SQL Server Management Studio to improve your times and execution plans
  • 48. Be Opinionated!Solicit feedback on database design before coding starts, not after.Ask for opinions, and share your opinions!More eyes = better database designMore ideas = better database designAnyone have any tips… or questions?
  • 49. ResourcesSQL Server Books Online http://msdn.microsoft.com/en-us/library/ms130214.aspxSQL Server 2008 Query Performance Turning Distilled by Grant Fritchey and Sajal DamComparing Tables Organized with Clustered Indexes versus Heapshttp://technet.microsoft.com/en-us/library/cc917672.aspxMS Index Design Guidelineshttp://msdn.microsoft.com/en-us/library/ms191195.aspxClustered Indexes vs. Nonclustered Indexes in SQL Serverhttp://digcode.com/default.aspx?page=ed51cde3-d979-4daf-afae-fa6192562ea9&article=443e9774-7d26-422d-a2f1-dbcafbb1e1fc&pc=5SQL Server Execution Plans (free e-book, registration required)http://www.sqlservercentral.com/articles/books/65831/Uncover Hidden Data to Optimize Application Performancehttp://msdn.microsoft.com/en-us/magazine/cc135978.aspxMy New Filing Technique is Unstoppable (NSFW)http://www.mnftiu.cc/2002/11/26/filing-001/SQL in the Wildhttp://sqlinthewild.co.za/Journey to SQL Authority With Pinal Davehttp://blog.sqlauthority.com/