SQL Server 2008 Development for Programmers(Level 200)Springfield .NET Users GroupJune 28th, 2011Presentation by Adam Hutson
Speaker Bio – Adam HutsonDatabase Developer at Expedia and a freelance developer.  11 year career, mostly on software side, on database side for past couple years.  Enjoy learning new development techniques, earning MSSQL certifications, and picking up various web & desktop development side projects. Married 8 yrs & 4 kiddos (B-6y, G-4y, G-2y, & G-5m)Blog: http://adamhutson.com/LinkedIn: http://www.linkedin.com/in/adamhutson
Presentation OverviewReview of CRUD & JOIN basicsDynamic vs. Compiled StatementsIndexes & Execution PlansPerformance IssuesScaling up your DatabasePersonal toolbox, templates, & links
CRUD basicsCreate  INSERT statementsINSERTMyTable(Col1, Col2)VALUES ('a','b')Read  SELECT statementsSELECT Col1, Col2 FROMMyTableUpdate  UPDATE statementsUPDATE MyTable SET Col1 = Col1 + Col1Delete  DELETE statementsDELETEFROMMyTableWHERE Col2 ='b'
JOIN basics[INNER] JOINLEFT [OUTER] JOINRIGHT [OUTER] JOINFULL [OUTER] JOINCROSS JOIN
[INNER] JOININNER Joins combine the matching records from 2 tables.  INNER keyword is optional.
LEFT [OUTER] JOINLEFT [OUTER] JOINs combine all the records from the left table and only the matching records from right table.  OUTER keyword is optional.
RIGHT [OUTER] JOINRIGHT [OUTER] JOINs combine all the records from the right table and only the matching records from left table.  OUTER keyword is optional.
FULL [OUTER] JOINFULL [OUTER] JOINs combine all rows from both tables regardless of match.  OUTER keyword is optional.
CROSS JOINCROSS JOINs provide a Cartesian product between two tables.  A Cartesian product contains all the rows from all the tables combined.
Dynamic vs. Compiled StatementsDynamic SQL StatementsConstructed at runtime with variable dataExecution plan is determined on 1stexecutionAny adhoc query is dynamic to the optimizerCompiled SQL StatementsConstructed at design timeExecution plan is known before executionStored Procedures are compiled
Execution PlansWhat is an execution plan?Query optimizer’s attempt to calculate the most efficient way to implement a query.Calculates the cost in terms of CPU, I/O, & speed.Where are they stored?Generating an execution plan is expensive, so they are stored for reuse in memory (plan cache).Are purged from memory using an aging formula that considers it’s cost and use
IndexesWhat are indexes?Catalog of locations and order of records in tableWhy use them?Speeds up queries; tables are just heaps of data without themTypes:Clustered NonClusteredCompositeUniqueCovering
Index storageAn index is a set of pages (index nodes) that are organized in a B-tree structure.Root LevelIntermediateLevelsLeaf Level
Clustered – stores the actual data rows at the leaf level of the index; physically sorted table; only 1 per tableNonClustered – leaf nodes contain only the values from the indexed columns and row locators to the actual data rows, not the actual data rows themselves; 249 per tableComposite – contains more than one column  up to 16; can be clustered or nonclustered; max of 900 bytesUnique – ensures each value in the indexed column is unique.  If composite, then the uniqueness is enforced across the columns as a whole. Defining a PK or unique constraint automatically creates a Unique indexCovering – includes all the columns that are needed to process a query; an extension of nonclustered functionality; adds non-key columns to the leaf level; not included when calculating number of index key columns or index key size.
If a table’s data changes frequently, keep indexes few, simple, & narrow.For tables with a lot of data and infrequent changes, use as many indexes as needed for performance.Create nonclustered indexes on columns used frequently in predicates and join conditions.Index columns with exact match queries.Don’t index small tables, a Table scan is quickerTry to keep predicate order the same as index orderPeriodically check DMVs for usage and for unused or missing indexes (sys.dm_db_index_usage_stats & sys.dm_db_missing_index_*)
Performance IssuesPossible causesBlockingCPU Bottlenecks Memory Bottlenecks I/O Bottlenecks Tools to IdentifyPerformance Monitor (PerfMon)SQL Server Profiler DBCC commandsDMVs
BlockingBlocking is primarily waits for logical locks, which occur when a request to acquire  a non-compatible lock on an already-locked resource is made.Identifying:DMVs: sys.dm_os_wait*, sys.dm_tran_locksProfiler: Deadlock graph & Blocked process report
CPU BottlenecksCan be caused by insufficient hardware, poor query tuning, or excessive query compilation.Identifying:PerfMon – “%Processor Time” > 80%, ratio of “SQL Recompilations / sec” to “Batch Requests / sec” be lowProfiler – watch SP:Recompile & SQL:StmtRecompile classesDMVs – sys.dm_exec_query_stats & sys.dm_exec_query_optimizer_info
Memory BottlenecksLow memory conditions, or memory pressureUse of AWE & VAS, actual physical memory, other applicationsIdentifying:Task ManagerPerformance Monitor – “Memory: Available”, “Process: Working Set”, “Paging File:*”DMVs – sys.dm_os_memory_*DBCC MEMORYSTATUS
I/O BottlenecksCheck memory first as it can cause I/OCheck execution plans for high I/OIdentifying:PerfMon – Avg Disk Queue, Avg Disk Sec/Read, Avg Disk Sec/Write, %Disk Time, Avg Disc Reads/Sec, Avg Disk Writes/SecDMVs – sys.dm_io_* & sys.dm_os_wait_stats where wait_type like 'PAGEIOLATCH%'
Scaling it all upSingle database design isn’t appropriate hereDesigns have to incorporate multiple databases over multiple servers with different characteristicsTransactional & Analytical needs are differentIndexing strategies are differentExecution plans should be scrutinizedPartitioning  becomes pertinent as current and archive data coexist
Personal toolbox, templates, & linksWatch my website and blog, I’ll post my toolbox of scripts, templates I use for object maintenance, and all the links I keep handy for referencing SQL topics.http://adamhutson.com

More Related Content

PPTX
Optimizing Your Cloud Applications in RightScale
PPTX
Oracle DB Performance Tuning Tips
PPTX
Query Optimization in SQL Server
PPTX
Database Performance Tuning
PPT
Performance Tuning And Optimization Microsoft SQL Database
PDF
Stream Processing with Pipelines and Stored Procedures
PDF
SQL Database Performance Tuning for Developers
PPTX
Stored procedure tuning and optimization t sql
Optimizing Your Cloud Applications in RightScale
Oracle DB Performance Tuning Tips
Query Optimization in SQL Server
Database Performance Tuning
Performance Tuning And Optimization Microsoft SQL Database
Stream Processing with Pipelines and Stored Procedures
SQL Database Performance Tuning for Developers
Stored procedure tuning and optimization t sql

What's hot (20)

PDF
New fordevelopersinsql server2008
PPTX
SQL Server Query Optimization, Execution and Debugging Query Performance
PPTX
Sql server introduction
PDF
MySQL & Expression Engine EEUK2013
PDF
Performance tuning in sql server
PPT
Less13 Performance
DOC
Hyperion essbase basics
PDF
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
DOCX
Calculation commands in essbase
PPTX
Getting to know oracle database objects iot, mviews, clusters and more…
PPTX
Large scale sql server best practices
PDF
The two faces of sql parameter sniffing
PDF
Why & how to optimize sql server for performance from design to query
PDF
Weblogic plug in
PDF
SQLDay2013_MarcinSzeliga_StoredProcedures
PDF
Brad McGehee Intepreting Execution Plans Mar09
PDF
Uncovering SQL Server query problems with execution plans - Tony Davis
PPT
resource governor
PPTX
Oracle performance tuning_sfsf
PDF
SQL Server Tuning to Improve Database Performance
New fordevelopersinsql server2008
SQL Server Query Optimization, Execution and Debugging Query Performance
Sql server introduction
MySQL & Expression Engine EEUK2013
Performance tuning in sql server
Less13 Performance
Hyperion essbase basics
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Calculation commands in essbase
Getting to know oracle database objects iot, mviews, clusters and more…
Large scale sql server best practices
The two faces of sql parameter sniffing
Why & how to optimize sql server for performance from design to query
Weblogic plug in
SQLDay2013_MarcinSzeliga_StoredProcedures
Brad McGehee Intepreting Execution Plans Mar09
Uncovering SQL Server query problems with execution plans - Tony Davis
resource governor
Oracle performance tuning_sfsf
SQL Server Tuning to Improve Database Performance
Ad

Viewers also liked (20)

PPTX
Alternatives to Relational Databases
PDF
Cassandra Summit: Data Modeling A Scheduling App
PPTX
SaaS Enablement Challenges & Approaches
PDF
Data Modeling with Cassandra and Time Series Data
PDF
Cassandra Summit 2015 - Building a multi-tenant API PaaS with DataStax Enterp...
PDF
Wayne State University & DataStax: World's best data modeling tool for Apache...
PDF
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
PDF
Time series with Apache Cassandra - Long version
PPTX
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
PDF
Cassandra By Example: Data Modelling with CQL3
PDF
Cassandra Explained
PDF
Sitting the Key Features Examination
PDF
HMI/UI Development Services - Bangalore, India
PPTX
Isaac slide show
PPT
Sint. proteínas
DOC
3er parcial anahuac
PPT
Resum Curs 2011 - 2012. Segona Part
PPS
Goazen kirofanora
PPTX
Budgetirovanie v 1 c 1
PPT
“Seguridad efectiva” Mikel Uriarte de Nextel S.A.
Alternatives to Relational Databases
Cassandra Summit: Data Modeling A Scheduling App
SaaS Enablement Challenges & Approaches
Data Modeling with Cassandra and Time Series Data
Cassandra Summit 2015 - Building a multi-tenant API PaaS with DataStax Enterp...
Wayne State University & DataStax: World's best data modeling tool for Apache...
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
Time series with Apache Cassandra - Long version
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
Cassandra By Example: Data Modelling with CQL3
Cassandra Explained
Sitting the Key Features Examination
HMI/UI Development Services - Bangalore, India
Isaac slide show
Sint. proteínas
3er parcial anahuac
Resum Curs 2011 - 2012. Segona Part
Goazen kirofanora
Budgetirovanie v 1 c 1
“Seguridad efectiva” Mikel Uriarte de Nextel S.A.
Ad

Similar to SQL Server 2008 Development for Programmers (20)

PPTX
SQL Server 2012 Best Practices
PPTX
Building scalable application with sql server
PPTX
Elegant and Efficient Database Design
PDF
Brad McGehee Intepreting Execution Plans Mar09
PDF
SQL Joins and Query Optimization
PDF
Backpack Tools4 Sql Dev
PPTX
Sql good practices
PPT
MS SQL Server.ppt sql
PPTX
02 database oprimization - improving sql performance - ent-db
PDF
Database development coding standards
PDF
Query Tuning for Database Pros & Developers
PPTX
Introduction to execution plan analysis
PPTX
Optimizing Application Performance - 2022.pptx
PDF
Speed up sql
PPT
MS SQL Server.ppt
PDF
Tips for Database Performance
PPTX
Database Performance
PPTX
It Depends
PPTX
Database optimization
PPT
Sql server introduction to sql server
SQL Server 2012 Best Practices
Building scalable application with sql server
Elegant and Efficient Database Design
Brad McGehee Intepreting Execution Plans Mar09
SQL Joins and Query Optimization
Backpack Tools4 Sql Dev
Sql good practices
MS SQL Server.ppt sql
02 database oprimization - improving sql performance - ent-db
Database development coding standards
Query Tuning for Database Pros & Developers
Introduction to execution plan analysis
Optimizing Application Performance - 2022.pptx
Speed up sql
MS SQL Server.ppt
Tips for Database Performance
Database Performance
It Depends
Database optimization
Sql server introduction to sql server

Recently uploaded (20)

PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Five Habits of High-Impact Board Members
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
STKI Israel Market Study 2025 version august
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
UiPath Agentic Automation session 1: RPA to Agents
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPT
Geologic Time for studying geology for geologist
PDF
Architecture types and enterprise applications.pdf
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Comparative analysis of machine learning models for fake news detection in so...
A contest of sentiment analysis: k-nearest neighbor versus neural network
Credit Without Borders: AI and Financial Inclusion in Bangladesh
Zenith AI: Advanced Artificial Intelligence
sustainability-14-14877-v2.pddhzftheheeeee
Five Habits of High-Impact Board Members
Custom Battery Pack Design Considerations for Performance and Safety
STKI Israel Market Study 2025 version august
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
Convolutional neural network based encoder-decoder for efficient real-time ob...
UiPath Agentic Automation session 1: RPA to Agents
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions
Module 1.ppt Iot fundamentals and Architecture
Final SEM Unit 1 for mit wpu at pune .pptx
Geologic Time for studying geology for geologist
Architecture types and enterprise applications.pdf
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor

SQL Server 2008 Development for Programmers

  • 1. SQL Server 2008 Development for Programmers(Level 200)Springfield .NET Users GroupJune 28th, 2011Presentation by Adam Hutson
  • 2. Speaker Bio – Adam HutsonDatabase Developer at Expedia and a freelance developer.  11 year career, mostly on software side, on database side for past couple years.  Enjoy learning new development techniques, earning MSSQL certifications, and picking up various web & desktop development side projects. Married 8 yrs & 4 kiddos (B-6y, G-4y, G-2y, & G-5m)Blog: http://adamhutson.com/LinkedIn: http://www.linkedin.com/in/adamhutson
  • 3. Presentation OverviewReview of CRUD & JOIN basicsDynamic vs. Compiled StatementsIndexes & Execution PlansPerformance IssuesScaling up your DatabasePersonal toolbox, templates, & links
  • 4. CRUD basicsCreate  INSERT statementsINSERTMyTable(Col1, Col2)VALUES ('a','b')Read  SELECT statementsSELECT Col1, Col2 FROMMyTableUpdate  UPDATE statementsUPDATE MyTable SET Col1 = Col1 + Col1Delete  DELETE statementsDELETEFROMMyTableWHERE Col2 ='b'
  • 5. JOIN basics[INNER] JOINLEFT [OUTER] JOINRIGHT [OUTER] JOINFULL [OUTER] JOINCROSS JOIN
  • 6. [INNER] JOININNER Joins combine the matching records from 2 tables. INNER keyword is optional.
  • 7. LEFT [OUTER] JOINLEFT [OUTER] JOINs combine all the records from the left table and only the matching records from right table. OUTER keyword is optional.
  • 8. RIGHT [OUTER] JOINRIGHT [OUTER] JOINs combine all the records from the right table and only the matching records from left table. OUTER keyword is optional.
  • 9. FULL [OUTER] JOINFULL [OUTER] JOINs combine all rows from both tables regardless of match. OUTER keyword is optional.
  • 10. CROSS JOINCROSS JOINs provide a Cartesian product between two tables. A Cartesian product contains all the rows from all the tables combined.
  • 11. Dynamic vs. Compiled StatementsDynamic SQL StatementsConstructed at runtime with variable dataExecution plan is determined on 1stexecutionAny adhoc query is dynamic to the optimizerCompiled SQL StatementsConstructed at design timeExecution plan is known before executionStored Procedures are compiled
  • 12. Execution PlansWhat is an execution plan?Query optimizer’s attempt to calculate the most efficient way to implement a query.Calculates the cost in terms of CPU, I/O, & speed.Where are they stored?Generating an execution plan is expensive, so they are stored for reuse in memory (plan cache).Are purged from memory using an aging formula that considers it’s cost and use
  • 13. IndexesWhat are indexes?Catalog of locations and order of records in tableWhy use them?Speeds up queries; tables are just heaps of data without themTypes:Clustered NonClusteredCompositeUniqueCovering
  • 14. Index storageAn index is a set of pages (index nodes) that are organized in a B-tree structure.Root LevelIntermediateLevelsLeaf Level
  • 15. Clustered – stores the actual data rows at the leaf level of the index; physically sorted table; only 1 per tableNonClustered – leaf nodes contain only the values from the indexed columns and row locators to the actual data rows, not the actual data rows themselves; 249 per tableComposite – contains more than one column up to 16; can be clustered or nonclustered; max of 900 bytesUnique – ensures each value in the indexed column is unique. If composite, then the uniqueness is enforced across the columns as a whole. Defining a PK or unique constraint automatically creates a Unique indexCovering – includes all the columns that are needed to process a query; an extension of nonclustered functionality; adds non-key columns to the leaf level; not included when calculating number of index key columns or index key size.
  • 16. If a table’s data changes frequently, keep indexes few, simple, & narrow.For tables with a lot of data and infrequent changes, use as many indexes as needed for performance.Create nonclustered indexes on columns used frequently in predicates and join conditions.Index columns with exact match queries.Don’t index small tables, a Table scan is quickerTry to keep predicate order the same as index orderPeriodically check DMVs for usage and for unused or missing indexes (sys.dm_db_index_usage_stats & sys.dm_db_missing_index_*)
  • 17. Performance IssuesPossible causesBlockingCPU Bottlenecks Memory Bottlenecks I/O Bottlenecks Tools to IdentifyPerformance Monitor (PerfMon)SQL Server Profiler DBCC commandsDMVs
  • 18. BlockingBlocking is primarily waits for logical locks, which occur when a request to acquire a non-compatible lock on an already-locked resource is made.Identifying:DMVs: sys.dm_os_wait*, sys.dm_tran_locksProfiler: Deadlock graph & Blocked process report
  • 19. CPU BottlenecksCan be caused by insufficient hardware, poor query tuning, or excessive query compilation.Identifying:PerfMon – “%Processor Time” > 80%, ratio of “SQL Recompilations / sec” to “Batch Requests / sec” be lowProfiler – watch SP:Recompile & SQL:StmtRecompile classesDMVs – sys.dm_exec_query_stats & sys.dm_exec_query_optimizer_info
  • 20. Memory BottlenecksLow memory conditions, or memory pressureUse of AWE & VAS, actual physical memory, other applicationsIdentifying:Task ManagerPerformance Monitor – “Memory: Available”, “Process: Working Set”, “Paging File:*”DMVs – sys.dm_os_memory_*DBCC MEMORYSTATUS
  • 21. I/O BottlenecksCheck memory first as it can cause I/OCheck execution plans for high I/OIdentifying:PerfMon – Avg Disk Queue, Avg Disk Sec/Read, Avg Disk Sec/Write, %Disk Time, Avg Disc Reads/Sec, Avg Disk Writes/SecDMVs – sys.dm_io_* & sys.dm_os_wait_stats where wait_type like 'PAGEIOLATCH%'
  • 22. Scaling it all upSingle database design isn’t appropriate hereDesigns have to incorporate multiple databases over multiple servers with different characteristicsTransactional & Analytical needs are differentIndexing strategies are differentExecution plans should be scrutinizedPartitioning becomes pertinent as current and archive data coexist
  • 23. Personal toolbox, templates, & linksWatch my website and blog, I’ll post my toolbox of scripts, templates I use for object maintenance, and all the links I keep handy for referencing SQL topics.http://adamhutson.com