SlideShare a Scribd company logo
1 of 18
Download to read offline
Pseudo-Constants
in SQL
@RileyMajor
These digits are misleading.
http://en.wikipedia.org/wiki/Washington_Park_MAX_Station
Infrequently
Changed
Frequently
Referenced
Pseudo-Constant Candidates
They’re everywhere…
•Sizes
•Order Statuses
•DEFCON Levels
4
Whole mess o’ strings…
•So much data.
•Performance problems.
•Consistency Issues.
•Inflexible names.
Use Lookup Tables
• Less Space
• Better
Performance
• Cleaner Data
• Numeric ID /
Textual ID /
Description
•Codes
•Enums
•Constants
•IDs
Magic
Numbers
Traditional Option:
Hard Coding
Did you find them all?
• Fast
• Easy
• Maintenance Nightmare
Better Option: JOINs to Lookup Tables
• Text Codes
• Slightly Slower
• More Complex
Query Plans
Best Option:
Pseudo-Constant
Functions
• Fast
• Compiler
Enforcement
• IntelliSense
10
Let’s dive in…
11
Pseudo-Constants
Inline Table-Valued
User Defined
Functions with a
Column Per Value
SELECT *
FROM dbo.CalcConstOrderStatuses() os
CROSS JOIN Orders AS o
WHERE o.OrderStatusID = os.OrderStatusAssigned;
•Ad-Hoc SQL
•Stored Procedures
•Views
•User-Defined Functions
•Persisted Calculated Columns
Apply Liberally
14
Do not take with… •Filtered Indexes
•Indexed Views
•OPTIMIZE FOR
Riley Wheeler Major
@RileyMajor
RileyMajor.com
PASSMN@RileyMajor.com
www.linkedin.com/in/rileymajor/
Enterprise Architect
Manna Freight Systems, Inc.
www.MFSCorporate.com
Director of Technology, PASSMN
mnssug.org
Photo Credits
Day 187: Tilt-Shift Miniature Fake
Snugg LePup
https://www.flickr.com/photos/snugglepup/
3741073220
Pi
Benjamin Chan
https://www.flickr.com/photos/benchan/4771478057
IMG_8549
Tantek Çelik
https://www.flickr.com/photos/tantek/272706097
yellow strings
M Glasgow
https://www.flickr.com/photos/glasgows/117229470
The Worlds Greatest Detective
Kit
https://www.flickr.com/photos/practicalowl/
1185217331
No more rabbits?
Kristina Alexanderson
https://www.flickr.com/photos/kalexanderson/
6163134201
Needle In A Haystack
t_buchtele
https://www.flickr.com/photos/t_buchtele/
3422507814
DSP 87: Wagon Ride 2007-08-12
Vern Hart
https://www.flickr.com/photos/vernhart/1143920492
Very excited for cake
Sean Donohue
https://www.flickr.com/photos/hermida/608166432
Everybody's Diving at the Beach
Diana Robinson
https://www.flickr.com/photos/dianasch/
Photo Credits (continued)
Hollywood Studios - Frozen Gertie
Jeff Krause
https://www.flickr.com/photos/jeffkrause/
14730139972
Reflections on the new Machine Age — technology,
inequality and the economy
Steve Jurvetson
https://www.flickr.com/photos/jurvetson/
16620787618
apply liberally for best results
Ryan M. Follow
https://www.flickr.com/photos/vancityscapes/
2499792217
pills
Dominique Godbout
https://www.flickr.com/photos/dominiquegodbout/
5180502739
Additional References:
SQL Saturday Link:
http://www.sqlsaturday.com/387/Sessions/Details.aspx?sid=21735
Misleading Engraved Pi Digits
http://www.o4sr.org/publications/pf_v4n3/PiUnderground.htm
Wisconsin PASS Chapters:
FoxPASS - Appleton, WI
MADPASS - Madison, WI
Microsoft BI Professionals - Wisconsin: Greendale, WI
Western Wisconsin PASS - Altoona, WI
WI SSUG - Waukesha, WI

More Related Content

What's hot

Relational databases
Relational databasesRelational databases
Relational databasesshams mshirb
 
Searching for The Matrix in haystack (with Elasticsearch)
Searching for The Matrix in haystack  (with Elasticsearch)Searching for The Matrix in haystack  (with Elasticsearch)
Searching for The Matrix in haystack (with Elasticsearch)Tomas Sirny
 
webclustering engine
webclustering enginewebclustering engine
webclustering engineDeepak Sharma
 
Database design
Database designDatabase design
Database designRiteshkiit
 
Extensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLTExtensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLTAshikur Rahman
 
Web forms and html (lect 4)
Web forms and html (lect 4)Web forms and html (lect 4)
Web forms and html (lect 4)Salman Memon
 
Designing Windows apps with Xaml
Designing Windows apps with XamlDesigning Windows apps with Xaml
Designing Windows apps with XamlJiri Danihelka
 
Database Indexes
Database IndexesDatabase Indexes
Database IndexesSperasoft
 

What's hot (10)

Relational databases
Relational databasesRelational databases
Relational databases
 
Searching for The Matrix in haystack (with Elasticsearch)
Searching for The Matrix in haystack  (with Elasticsearch)Searching for The Matrix in haystack  (with Elasticsearch)
Searching for The Matrix in haystack (with Elasticsearch)
 
webclustering engine
webclustering enginewebclustering engine
webclustering engine
 
Database design
Database designDatabase design
Database design
 
Extensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLTExtensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLT
 
Web forms and html (lect 4)
Web forms and html (lect 4)Web forms and html (lect 4)
Web forms and html (lect 4)
 
Chapter4
Chapter4Chapter4
Chapter4
 
Designing Windows apps with Xaml
Designing Windows apps with XamlDesigning Windows apps with Xaml
Designing Windows apps with Xaml
 
Database Indexes
Database IndexesDatabase Indexes
Database Indexes
 
SQL_Part1
SQL_Part1SQL_Part1
SQL_Part1
 

Viewers also liked

Film beginning analysis
Film beginning analysisFilm beginning analysis
Film beginning analysismrwalkerben
 
Dmmp assignment post 2
Dmmp assignment post 2Dmmp assignment post 2
Dmmp assignment post 2sipnbite
 
2015-08-12 - Open Up the Clubhouse - With Notes
2015-08-12 - Open Up the Clubhouse - With Notes2015-08-12 - Open Up the Clubhouse - With Notes
2015-08-12 - Open Up the Clubhouse - With NotesRiley Major
 
Genre analysis - Crime Fiction/Comedy
Genre analysis - Crime Fiction/ComedyGenre analysis - Crime Fiction/Comedy
Genre analysis - Crime Fiction/Comedymrwalkerben
 
Actors, Outside Location, Costume and Props - Code 5
Actors, Outside Location, Costume and Props - Code 5Actors, Outside Location, Costume and Props - Code 5
Actors, Outside Location, Costume and Props - Code 5mrwalkerben
 
AS Media Pre-Production Marks Sheet
AS Media Pre-Production Marks SheetAS Media Pre-Production Marks Sheet
AS Media Pre-Production Marks Sheetmrwalkerben
 
Social media
Social mediaSocial media
Social mediasipnbite
 
Dmmp assignment post 2
Dmmp assignment post 2Dmmp assignment post 2
Dmmp assignment post 2sipnbite
 
Narrative Theories and Theorists
Narrative Theories and TheoristsNarrative Theories and Theorists
Narrative Theories and Theoristsmrwalkerben
 
Chapter 9- Differentiation Add Maths Form 4 SPM
Chapter 9- Differentiation Add Maths Form 4 SPMChapter 9- Differentiation Add Maths Form 4 SPM
Chapter 9- Differentiation Add Maths Form 4 SPMyw t
 
Permasalahan Penataan Ruang di Daerah
Permasalahan Penataan Ruang di DaerahPermasalahan Penataan Ruang di Daerah
Permasalahan Penataan Ruang di Daerahhenny ferniza
 

Viewers also liked (14)

Film beginning analysis
Film beginning analysisFilm beginning analysis
Film beginning analysis
 
Dmmp assignment post 2
Dmmp assignment post 2Dmmp assignment post 2
Dmmp assignment post 2
 
2015-08-12 - Open Up the Clubhouse - With Notes
2015-08-12 - Open Up the Clubhouse - With Notes2015-08-12 - Open Up the Clubhouse - With Notes
2015-08-12 - Open Up the Clubhouse - With Notes
 
Genre analysis - Crime Fiction/Comedy
Genre analysis - Crime Fiction/ComedyGenre analysis - Crime Fiction/Comedy
Genre analysis - Crime Fiction/Comedy
 
Actors, Outside Location, Costume and Props - Code 5
Actors, Outside Location, Costume and Props - Code 5Actors, Outside Location, Costume and Props - Code 5
Actors, Outside Location, Costume and Props - Code 5
 
AS Media Pre-Production Marks Sheet
AS Media Pre-Production Marks SheetAS Media Pre-Production Marks Sheet
AS Media Pre-Production Marks Sheet
 
Impact_of_Basel_III_published_2012Feb
Impact_of_Basel_III_published_2012FebImpact_of_Basel_III_published_2012Feb
Impact_of_Basel_III_published_2012Feb
 
Reciclaje y decoración
Reciclaje y decoración Reciclaje y decoración
Reciclaje y decoración
 
Social media
Social mediaSocial media
Social media
 
Dmmp assignment post 2
Dmmp assignment post 2Dmmp assignment post 2
Dmmp assignment post 2
 
Narrative Theories and Theorists
Narrative Theories and TheoristsNarrative Theories and Theorists
Narrative Theories and Theorists
 
Media Language
Media LanguageMedia Language
Media Language
 
Chapter 9- Differentiation Add Maths Form 4 SPM
Chapter 9- Differentiation Add Maths Form 4 SPMChapter 9- Differentiation Add Maths Form 4 SPM
Chapter 9- Differentiation Add Maths Form 4 SPM
 
Permasalahan Penataan Ruang di Daerah
Permasalahan Penataan Ruang di DaerahPermasalahan Penataan Ruang di Daerah
Permasalahan Penataan Ruang di Daerah
 

Similar to 2015-04-11-PseudoConstants

Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptxIke Ellis
 
Introduction to Apache Cassandra
Introduction to Apache CassandraIntroduction to Apache Cassandra
Introduction to Apache CassandraJesus Guzman
 
Cassandra Summit 2014: Fuzzy Entity Matching at Scale
Cassandra Summit 2014: Fuzzy Entity Matching at ScaleCassandra Summit 2014: Fuzzy Entity Matching at Scale
Cassandra Summit 2014: Fuzzy Entity Matching at ScaleDataStax Academy
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - ENGianluca Sartori
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleChristophe Grand
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationAndrew Siemer
 
Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Jon Haddad
 
Cassandra Day London 2015: Introduction to Apache Cassandra and DataStax Ente...
Cassandra Day London 2015: Introduction to Apache Cassandra and DataStax Ente...Cassandra Day London 2015: Introduction to Apache Cassandra and DataStax Ente...
Cassandra Day London 2015: Introduction to Apache Cassandra and DataStax Ente...DataStax Academy
 
Cassandra Day Atlanta 2015: Introduction to Apache Cassandra & DataStax Enter...
Cassandra Day Atlanta 2015: Introduction to Apache Cassandra & DataStax Enter...Cassandra Day Atlanta 2015: Introduction to Apache Cassandra & DataStax Enter...
Cassandra Day Atlanta 2015: Introduction to Apache Cassandra & DataStax Enter...DataStax Academy
 
Cassandra Day Chicago 2015: Introduction to Apache Cassandra & DataStax Enter...
Cassandra Day Chicago 2015: Introduction to Apache Cassandra & DataStax Enter...Cassandra Day Chicago 2015: Introduction to Apache Cassandra & DataStax Enter...
Cassandra Day Chicago 2015: Introduction to Apache Cassandra & DataStax Enter...DataStax Academy
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLRichard Schneeman
 
Apache Solr 1.4 – Faster, Easier, and More Versatile than Ever
Apache Solr 1.4 – Faster, Easier, and More Versatile than EverApache Solr 1.4 – Faster, Easier, and More Versatile than Ever
Apache Solr 1.4 – Faster, Easier, and More Versatile than EverLucidworks (Archived)
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
Writing High Peformance C# 7 Code
Writing High Peformance C# 7 CodeWriting High Peformance C# 7 Code
Writing High Peformance C# 7 CodeFons Sonnemans
 
Introduction to Cassandra - Denver
Introduction to Cassandra - DenverIntroduction to Cassandra - Denver
Introduction to Cassandra - DenverJon Haddad
 
Cassandra Day Denver 2014: Introduction to Apache Cassandra
Cassandra Day Denver 2014: Introduction to Apache CassandraCassandra Day Denver 2014: Introduction to Apache Cassandra
Cassandra Day Denver 2014: Introduction to Apache CassandraDataStax Academy
 
Performance By Design
Performance By DesignPerformance By Design
Performance By DesignGuy Harrison
 

Similar to 2015-04-11-PseudoConstants (20)

Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
 
Introduction to Apache Cassandra
Introduction to Apache CassandraIntroduction to Apache Cassandra
Introduction to Apache Cassandra
 
Cassandra Summit 2014: Fuzzy Entity Matching at Scale
Cassandra Summit 2014: Fuzzy Entity Matching at ScaleCassandra Summit 2014: Fuzzy Entity Matching at Scale
Cassandra Summit 2014: Fuzzy Entity Matching at Scale
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - EN
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregation
 
Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)
 
Cassandra Day London 2015: Introduction to Apache Cassandra and DataStax Ente...
Cassandra Day London 2015: Introduction to Apache Cassandra and DataStax Ente...Cassandra Day London 2015: Introduction to Apache Cassandra and DataStax Ente...
Cassandra Day London 2015: Introduction to Apache Cassandra and DataStax Ente...
 
Cassandra Day Atlanta 2015: Introduction to Apache Cassandra & DataStax Enter...
Cassandra Day Atlanta 2015: Introduction to Apache Cassandra & DataStax Enter...Cassandra Day Atlanta 2015: Introduction to Apache Cassandra & DataStax Enter...
Cassandra Day Atlanta 2015: Introduction to Apache Cassandra & DataStax Enter...
 
Cassandra Day Chicago 2015: Introduction to Apache Cassandra & DataStax Enter...
Cassandra Day Chicago 2015: Introduction to Apache Cassandra & DataStax Enter...Cassandra Day Chicago 2015: Introduction to Apache Cassandra & DataStax Enter...
Cassandra Day Chicago 2015: Introduction to Apache Cassandra & DataStax Enter...
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
 
How to choose a database
How to choose a databaseHow to choose a database
How to choose a database
 
Apache Solr 1.4 – Faster, Easier, and More Versatile than Ever
Apache Solr 1.4 – Faster, Easier, and More Versatile than EverApache Solr 1.4 – Faster, Easier, and More Versatile than Ever
Apache Solr 1.4 – Faster, Easier, and More Versatile than Ever
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
Writing High Peformance C# 7 Code
Writing High Peformance C# 7 CodeWriting High Peformance C# 7 Code
Writing High Peformance C# 7 Code
 
Day 4 - Models
Day 4 - ModelsDay 4 - Models
Day 4 - Models
 
Introduction to Cassandra - Denver
Introduction to Cassandra - DenverIntroduction to Cassandra - Denver
Introduction to Cassandra - Denver
 
Cassandra Day Denver 2014: Introduction to Apache Cassandra
Cassandra Day Denver 2014: Introduction to Apache CassandraCassandra Day Denver 2014: Introduction to Apache Cassandra
Cassandra Day Denver 2014: Introduction to Apache Cassandra
 
Sql server infernals
Sql server infernalsSql server infernals
Sql server infernals
 
Performance By Design
Performance By DesignPerformance By Design
Performance By Design
 

2015-04-11-PseudoConstants