SlideShare a Scribd company logo
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
Ad

Recommended

Optimizing Your Cloud Applications in RightScale
Optimizing Your Cloud Applications in RightScale
RightScale
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
Asanka Dilruk
 
Query Optimization in SQL Server
Query Optimization in SQL Server
Rajesh Gunasundaram
 
Database Performance Tuning
Database Performance Tuning
Arno Huetter
 
Performance Tuning And Optimization Microsoft SQL Database
Performance Tuning And Optimization Microsoft SQL Database
Tung Nguyen Thanh
 
Stream Processing with Pipelines and Stored Procedures
Stream Processing with Pipelines and Stored Procedures
SingleStore
 
SQL Database Performance Tuning for Developers
SQL Database Performance Tuning for Developers
BRIJESH KUMAR
 
Stored procedure tuning and optimization t sql
Stored procedure tuning and optimization t sql
nishantdavid9
 
New fordevelopersinsql server2008
New fordevelopersinsql server2008
Aaron Shilo
 
SQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query Performance
Vinod Kumar
 
Sql server introduction
Sql server introduction
Riteshkiit
 
MySQL & Expression Engine EEUK2013
MySQL & Expression Engine EEUK2013
EEvolutionUK
 
Performance tuning in sql server
Performance tuning in sql server
Antonios Chatzipavlis
 
Less13 Performance
Less13 Performance
vivaankumar
 
Hyperion essbase basics
Hyperion essbase basics
Amit Sharma
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
Calculation commands in essbase
Calculation commands in essbase
Shoheb Mohammad
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
Aaron Shilo
 
Large scale sql server best practices
Large scale sql server best practices
mprabhuram
 
The two faces of sql parameter sniffing
The two faces of sql parameter sniffing
Ivo Andreev
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Weblogic plug in
Weblogic plug in
Aditya Bhuyan
 
SQLDay2013_MarcinSzeliga_StoredProcedures
SQLDay2013_MarcinSzeliga_StoredProcedures
Polish SQL Server User Group
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
guest9d79e073
 
Uncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony Davis
Red Gate Software
 
resource governor
resource governor
Aaron Shilo
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsf
Mao Geng
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database Performance
Mark Ginnebaugh
 
Alternatives to Relational Databases
Alternatives to Relational Databases
Adam Hutson
 
Cassandra Summit: Data Modeling A Scheduling App
Cassandra Summit: Data Modeling A Scheduling App
Adam Hutson
 

More Related Content

What's hot (20)

New fordevelopersinsql server2008
New fordevelopersinsql server2008
Aaron Shilo
 
SQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query Performance
Vinod Kumar
 
Sql server introduction
Sql server introduction
Riteshkiit
 
MySQL & Expression Engine EEUK2013
MySQL & Expression Engine EEUK2013
EEvolutionUK
 
Performance tuning in sql server
Performance tuning in sql server
Antonios Chatzipavlis
 
Less13 Performance
Less13 Performance
vivaankumar
 
Hyperion essbase basics
Hyperion essbase basics
Amit Sharma
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
Calculation commands in essbase
Calculation commands in essbase
Shoheb Mohammad
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
Aaron Shilo
 
Large scale sql server best practices
Large scale sql server best practices
mprabhuram
 
The two faces of sql parameter sniffing
The two faces of sql parameter sniffing
Ivo Andreev
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Weblogic plug in
Weblogic plug in
Aditya Bhuyan
 
SQLDay2013_MarcinSzeliga_StoredProcedures
SQLDay2013_MarcinSzeliga_StoredProcedures
Polish SQL Server User Group
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
guest9d79e073
 
Uncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony Davis
Red Gate Software
 
resource governor
resource governor
Aaron Shilo
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsf
Mao Geng
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database Performance
Mark Ginnebaugh
 
New fordevelopersinsql server2008
New fordevelopersinsql server2008
Aaron Shilo
 
SQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query Performance
Vinod Kumar
 
Sql server introduction
Sql server introduction
Riteshkiit
 
MySQL & Expression Engine EEUK2013
MySQL & Expression Engine EEUK2013
EEvolutionUK
 
Less13 Performance
Less13 Performance
vivaankumar
 
Hyperion essbase basics
Hyperion essbase basics
Amit Sharma
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
Calculation commands in essbase
Calculation commands in essbase
Shoheb Mohammad
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
Aaron Shilo
 
Large scale sql server best practices
Large scale sql server best practices
mprabhuram
 
The two faces of sql parameter sniffing
The two faces of sql parameter sniffing
Ivo Andreev
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
guest9d79e073
 
Uncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony Davis
Red Gate Software
 
resource governor
resource governor
Aaron Shilo
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsf
Mao Geng
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database Performance
Mark Ginnebaugh
 

Viewers also liked (20)

Alternatives to Relational Databases
Alternatives to Relational Databases
Adam Hutson
 
Cassandra Summit: Data Modeling A Scheduling App
Cassandra Summit: Data Modeling A Scheduling App
Adam Hutson
 
SaaS Enablement Challenges & Approaches
SaaS Enablement Challenges & Approaches
Impetus Technologies
 
Data Modeling with Cassandra and Time Series Data
Data Modeling with Cassandra and Time Series Data
Dani Traphagen
 
Cassandra Summit 2015 - Building a multi-tenant API PaaS with DataStax Enterp...
Cassandra Summit 2015 - Building a multi-tenant API PaaS with DataStax Enterp...
Restlet
 
Wayne State University & DataStax: World's best data modeling tool for Apache...
Wayne State University & DataStax: World's best data modeling tool for Apache...
DataStax Academy
 
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
DataStax
 
Time series with Apache Cassandra - Long version
Time series with Apache Cassandra - Long version
Patrick McFadin
 
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
DataStax
 
Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3
Eric Evans
 
Cassandra Explained
Cassandra Explained
Eric Evans
 
Sitting the Key Features Examination
Sitting the Key Features Examination
HMVT Teaching and Learning Space
 
HMI/UI Development Services - Bangalore, India
HMI/UI Development Services - Bangalore, India
Embitel Technologies - A VOLKSWAGEN GROUP COMPANY
 
Sint. proteínas
Sint. proteínas
Roma29
 
3er parcial anahuac
3er parcial anahuac
Roma29
 
Resum Curs 2011 - 2012. Segona Part
Resum Curs 2011 - 2012. Segona Part
Oliverasqv
 
Budgetirovanie v 1 c 1
Budgetirovanie v 1 c 1
Razdolie73
 
“Seguridad efectiva” Mikel Uriarte de Nextel S.A.
“Seguridad efectiva” Mikel Uriarte de Nextel S.A.
Nextel S.A.
 
Alternatives to Relational Databases
Alternatives to Relational Databases
Adam Hutson
 
Cassandra Summit: Data Modeling A Scheduling App
Cassandra Summit: Data Modeling A Scheduling App
Adam Hutson
 
SaaS Enablement Challenges & Approaches
SaaS Enablement Challenges & Approaches
Impetus Technologies
 
Data Modeling with Cassandra and Time Series Data
Data Modeling with Cassandra and Time Series Data
Dani Traphagen
 
Cassandra Summit 2015 - Building a multi-tenant API PaaS with DataStax Enterp...
Cassandra Summit 2015 - Building a multi-tenant API PaaS with DataStax Enterp...
Restlet
 
Wayne State University & DataStax: World's best data modeling tool for Apache...
Wayne State University & DataStax: World's best data modeling tool for Apache...
DataStax Academy
 
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
Data Modeling a Scheduling App (Adam Hutson, DataScale) | Cassandra Summit 2016
DataStax
 
Time series with Apache Cassandra - Long version
Time series with Apache Cassandra - Long version
Patrick McFadin
 
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
DataStax
 
Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3
Eric Evans
 
Cassandra Explained
Cassandra Explained
Eric Evans
 
Sint. proteínas
Sint. proteínas
Roma29
 
3er parcial anahuac
3er parcial anahuac
Roma29
 
Resum Curs 2011 - 2012. Segona Part
Resum Curs 2011 - 2012. Segona Part
Oliverasqv
 
Budgetirovanie v 1 c 1
Budgetirovanie v 1 c 1
Razdolie73
 
“Seguridad efectiva” Mikel Uriarte de Nextel S.A.
“Seguridad efectiva” Mikel Uriarte de Nextel S.A.
Nextel S.A.
 
Ad

Similar to SQL Server 2008 Development for Programmers (20)

SQL Server 2012 Best Practices
SQL Server 2012 Best Practices
Microsoft TechNet - Belgium and Luxembourg
 
Building scalable application with sql server
Building scalable application with sql server
Chris Adkin
 
Elegant and Efficient Database Design
Elegant and Efficient Database Design
Becky Sweger
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
Mark Ginnebaugh
 
SQL Joins and Query Optimization
SQL Joins and Query Optimization
Brian Gallagher
 
Backpack Tools4 Sql Dev
Backpack Tools4 Sql Dev
Gonçalo Chaves
 
Sql good practices
Sql good practices
Deepak Mehtani
 
MS SQL Server.ppt sql
MS SQL Server.ppt sql
NaheedBaloxh
 
02 database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Database development coding standards
Database development coding standards
Alessandro Baratella
 
Query Tuning for Database Pros & Developers
Query Tuning for Database Pros & Developers
Code Mastery
 
Introduction to execution plan analysis
Introduction to execution plan analysis
John Sterrett
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptx
JasonTuran2
 
Speed up sql
Speed up sql
Kaing Menglieng
 
MS SQL Server.ppt
MS SQL Server.ppt
QuyVo27
 
Tips for Database Performance
Tips for Database Performance
Kesavan Munuswamy
 
Database Performance
Database Performance
Boris Hristov
 
It Depends
It Depends
Maggie Pint
 
Database optimization
Database optimization
EsraaAlattar1
 
Sql server introduction to sql server
Sql server introduction to sql server
Vibrant Technologies & Computers
 
Building scalable application with sql server
Building scalable application with sql server
Chris Adkin
 
Elegant and Efficient Database Design
Elegant and Efficient Database Design
Becky Sweger
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
Mark Ginnebaugh
 
SQL Joins and Query Optimization
SQL Joins and Query Optimization
Brian Gallagher
 
MS SQL Server.ppt sql
MS SQL Server.ppt sql
NaheedBaloxh
 
02 database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Database development coding standards
Database development coding standards
Alessandro Baratella
 
Query Tuning for Database Pros & Developers
Query Tuning for Database Pros & Developers
Code Mastery
 
Introduction to execution plan analysis
Introduction to execution plan analysis
John Sterrett
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptx
JasonTuran2
 
MS SQL Server.ppt
MS SQL Server.ppt
QuyVo27
 
Tips for Database Performance
Tips for Database Performance
Kesavan Munuswamy
 
Database Performance
Database Performance
Boris Hristov
 
Database optimization
Database optimization
EsraaAlattar1
 
Ad

Recently uploaded (20)

You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 

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