SlideShare a Scribd company logo
1 of 21
Download to read offline
1
2 
PHIL FACTOR 
GRANT FRITCHEY 
K. BRIAN KELLEY 
MICKEY STUEWE 
IKE ELLIS 
JONATHAN ALLEN 
LOUIS DAVIDSON
Database 
Performance 
Tips for 
Developers 
As a developer, you may or may not need to go into 
the database and write queries, or design tables and 
indexes, or help determine configuration of your SQL 
Server systems. But if you do, these tips should help 
to make that a more pain free process.
4 
Contents 
Tips 1-5 
ORM Tips 
Tips 6-24 
T-SQL Tips 
Tips 25-40 
Index Tips 
Tips 41-45 
Database Design Tips 
5 
7 
12 
17
5 
ORM Tips 
More and more people are using Object to Relational Mapping 
(ORM) tools to jump the divide between application code that is 
object oriented and a database that stores information in a relational 
manner. These tools are excellent and radically improve development 
speed, but there are a few ‘gotchas’ to know about. 
1 Avoid following the ‘Hello World’ examples provided 
with your ORM tool that turns it into an Object to 
Object Mapping. Database storage is not the same as 
objects for a reason. You should still have a relational 
storage design within a relational storage engine such 
as SQL Server. 
Parameterized queries are exactly the same as stored 
procedures in terms of performance and memory 
management. Since most ORM tools can use either 
stored procedures or parameterized queries, be sure 
you’re coding to these constructs and not hard-coding 
values into your T-SQL queries. 
2
6 
Create, Read, Update, and Delete (CRUD) queries can 
all be generated from the ORM tool without the need 
for intervention. But, the Read queries generated are 
frequently very inefficient. Consider writing a stored 
procedure for complex Read queries. 
Since the code generated from the ORM can frequently 
be ad hoc, ensure that the SQL Server instance has 
‘Optimize for Ad Hoc’ enabled. This will store a plan 
stub in memory the first time a query is passed, rather 
than storing a full plan. This can help with memory 
management. 
Be sure your code is generating a parameter size 
equivalent to the data type defined within the table in 
the database. Some ORM tools size the parameter to 
the size of the value passed. This can lead to serious 
performance problems. 
3 
4 
5
7 
T-SQL Tips 
While much of your code may be generated, at least some of it will 
have to be written by hand. If you are writing some or all of your 
T-SQL code, these tips will help you avoid problems. 
SELECT * is not always a bad thing, but it’s a good idea 
to only move the data you really need to move and only 
when you really need it, in order to avoid network, disk, 
and memory contention on your server. 
Keep transactions as short as possible 
and never use them unnecessarily. 
The longer a lock is held the more 
likely it is that another user will be 
blocked. Never hold a transaction 
open after control is passed back 
to the application – use optimistic 
locking instead. 
6 
7 
For small sets of data that are 
infrequently updated such as lookup 
values, build a method of caching 
them in memory on your application 
server rather than constantly querying 
them in the database. 
8
8 
If doing processing within a transaction, leave the 
updates until last if possible, to minimize the need for 
exclusive locks. 
Cursors within SQL Server can cause severe 
performance bottlenecks. Avoid them. The WHILE loop 
within SQL Server is just as bad as a cursor. 
Ensure your variables and parameters are the same data 
types as the columns. An implicit or explicit conversion 
can lead to table scans and slow performance. 
9 
10 
11 
A function on columns in the WHERE clause or JOIN 
criteria means that SQL Server can’t use indexes 
appropriately and will lead to table scans and slow 
performance. 
12
9 
Don’t use DISTINCT, ORDER BY, or UNION 
unnecessarily. 
Table variables have no statistics within SQL Server. 
This makes them useful for working in situations where 
a statement level recompile can slow performance. But, 
that lack of statistics makes them very inefficient where 
you need to do searches or joins. Use table variables only 
where appropriate. 
13 
14 
Multi-statement user-defined functions work through 
table variables. Because of this, they also don’t work well 
in situations where statistics are required. If a join or 
filtering is required, avoid using them, especially if you 
are working with more than approximately 50 rows in 
the data set. 
15
10 
Query hints are actually commands to the query 
optimizer to control how a query plan is generated. 
These should be used very sparingly and only where 
appropriate. 
One of the most abused query hints is NO_LOCK. This 
can lead to extra or missing rows in data sets. Instead 
of using NO_LOCK consider using a snapshot isolation 
level such as READ_COMMITTED_SNAPSHOT. 
16 
17 
Avoid creating stored procedures that have a wide range 
of data supplied to them as parameters. These are 
compiled to use just one query plan. 18 
Try not to interleave data definition language with your 
data manipulation language queries within SQL Server. 
This can lead to recompiles which hurts performance. 19 
Temporary tables have statistics which get updated as 
data is inserted into them. As these updates occur, you 
can get recompiles. Where possible, substitute table 
variables to avoid this issue. 
20
11 
If possible, avoid NULL values in your database. If not, 
use the appropriate IS NULL and IS NOT NULL code. 21 
A view is meant to mask or modify how tables are 
presented to the end user. These are fine constructs. But 
when you start joining one view to another or nesting 
views within views, performance will suffer. Refer only 
to tables within a view. 
22 
Use extended 
events to monitor 
the queries in your 
system in order 
to identify slow 
running queries. 
If you’re on a 2005 
or earlier system 
you’ll need to use a 
server-side trace. 
24 
If you need to insert many rows at once into a table, 
use, where possible, the multi-row VALUES clause in 
INSERT statements. 23
12 
Index Tips 
Indexing tables is not an exact science. It requires some trial and 
error combined with lots of testing to get things just right. Even then, 
the performance metrics will change over time as you add more and 
more data. 
You get exactly one clustered index on a table. Ensure 
you have it in the right place. First choice is the most 
frequently accessed column, which may or may not 
be the primary key. Second choice is a column that 
structures the storage in a way that helps performance. 
This is a must for partitioning data. 
Clustered indexes work well on columns that are used 
a lot for ‘range’ WHERE clauses such as BETWEEN and 
LIKE, where it is frequently used in ORDER BY clauses 
or in GROUP BY clauses. 
25 
26
13 
If clustered indexes are narrow (involve few columns) 
then this will mean that less storage is needed for non-clustered 
indexes for that table. 
You do not have to make the primary key the clustered 
index. This is default behavior but can be directly 
controlled. 
You should have a clustered index on every table in 
the database. There are exceptions, but the exceptions 
should be exceptional. 
27 
28 
29 
Avoid using a column in a clustered index that has 
values that are frequently updated. 30
14 
Only create non-clustered indexes on tables when you 
know they’ll be used through testing. You can seriously 
hurt performance by creating too many indexes on a 
table. 
Keep your indexes as narrow as possible. This means 
reducing the number and size of the columns used in 
the index key. This helps make the index more efficient. 
31 
32 
Always index your foreign key columns if you are likely 
to delete rows from the referenced table. This avoids a 
table scan. 33
15 
A clustered index on a GUID can lead to serious 
fragmentation of the index due to the random 
nature of the GUID. You can use the function 
NEWSEQUENTIALID() to generate a GUID that will 
not lead to as much fragmentation. 
Performance is enhanced when indexes are placed on 
columns used in WHERE, JOIN, ORDER BY, GROUP, 
and TOP. Always test to ensure that the index does help 
performance. 
34 
35 
If a non-clustered index is useful to your queries, but 
doesn’t have all the columns needed by the query, you 
can consider using the INCLUDE option to store the 
extra columns at the leaf level of the index. 
36
16 
If temporary tables are in use, you can add indexes to 
those tables to enhance their performance. 
Where possible, make the indexes unique. This is 
especially true of the clustered index (one of the reasons 
that the primary key is by default clustered). A unique 
index absolutely performs faster than a non-unique 
index, even with the same values. 
37 
38 
Ensure that the selectivity of the data in the indexes is 
high. Very few unique values makes an index much less 
likely to be used well by the query optimizer. 
It is almost always better to let SQL Server update 
statistics automatically. 
39 
40
17 
Database Design Tips 
Again, you may not be delving much into this, but there are a few tips 
to keep in mind. 
While it is possible to over-normalize a database, 
under-normalization is much more prevalent. This 
leads to repetition of data, inefficient storage, and poor 
performance. Data normalization is a performance 
tuning technique as well as a storage mechanism. 
Referential integrity constraints such as foreign keys 
actually help performance, because the optimizer can 
recognize these enforced constraints and make better 
choices for joins and other data access. 
41 
42
18 
Make sure your database doesn’t hold ‘historic’ data 
that is no longer used. Archive it out, either into a 
special ‘archive’ database, a reporting OLAP database, 
or on file. Large tables mean longer table scans and 
deeper indexes. This in turn can mean that locks are 
held for longer. Admin tasks such as Statistics 
updates, DBCC checks, and index builds take longer, 
as do backups. 
Separate out the reporting functions from the OLTP 
production functions. OLTP databases usually have 
short transactions with a lot of updates whereas 
reporting databases, such as OLAP and data warehouse 
systems, have longer data-heavy queries. If possible, put 
them on different servers. 
44 
45 
Unique constraints also help performance because the 
optimizer can use these in different ways to enhance its 
query tuning. 43
19 
Tools 
SQL Prompt 
Write, refactor, and explore SQL effortlessly with this 
SQL Server Management Studio plug-in. 
SQL Compare 
Compare database schemas and deploy database 
schema changes. 
SQL Source Control 
Connect your databases to your version control system 
within SQL Server Management Studio. 
SQL Backup Pro 
Schedule backup jobs, verify with DBCC CHECKDB, and 
compress backups by up to 95%. 
SQL Index Manager 
Analyze, manage, and fix database index fragmentation.
20 
Books 
SQL Server Execution Plans 
by Grant Fritchey 
Learn the basics of capturing plans, how to interrupt 
them in their various forms, graphical or XML, and then 
how to use the information you find. Diagnose the most 
common causes of poor query performance so you 
can optimize your SQL queries and improve your 
indexing strategy. 
SQL Server Concurrency: Locking, Blocking 
and Row Versioning 
by Kalen Delaney 
Your application can have world-class indexes and 
queries, but they won’t help you if you can’t get your data 
because another application has it locked. That’s why 
every DBA and developer must understand SQL Server 
concurrency, and how to troubleshoot any issues. 
SQL Server Transaction Log Management 
by Tony Davis and Gail Shaw 
Tony Davis and Gail Shaw strive to offer just the right level 
of detail so that every DBA can perform all of the most 
important aspects of transaction log management.
21 
Troubleshooting SQL Server: A Guide for the 
Accidental DBA 
by Jonathan Kehayias and Ted Krueger 
Three SQL Server MVPs provide fascinating insight into 
the most common SQL Server problems, why they occur, 
and how they can be diagnosed using tools such as 
Performance Monitor, Dynamic Management Views, and 
server-side tracing performance, so you can optimize 
your SQL queries and improve your indexing strategy. 
Defensive Database Programming 
by Alex Kuznetsov 
The goal of defensive database programming is to 
help you to produce resilient T-SQL code that robustly 
and gracefully handles cases of unintended use, 
and is resilient to common changes to the database 
environment.

More Related Content

What's hot

Web Cloud Computing SQL Server - Ferrara University
Web Cloud Computing SQL Server  -  Ferrara UniversityWeb Cloud Computing SQL Server  -  Ferrara University
Web Cloud Computing SQL Server - Ferrara Universityantimo musone
 
Understanding System Performance
Understanding System PerformanceUnderstanding System Performance
Understanding System PerformanceTeradata
 
Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Dalia Saeed
 
SQL Server 2016 new features
SQL Server 2016 new featuresSQL Server 2016 new features
SQL Server 2016 new featuresSpanishPASSVC
 
Obiee11g working with partitions
Obiee11g working with partitionsObiee11g working with partitions
Obiee11g working with partitionsAmit Sharma
 
Learn SAS Programming
Learn SAS ProgrammingLearn SAS Programming
Learn SAS ProgrammingSASTechies
 

What's hot (6)

Web Cloud Computing SQL Server - Ferrara University
Web Cloud Computing SQL Server  -  Ferrara UniversityWeb Cloud Computing SQL Server  -  Ferrara University
Web Cloud Computing SQL Server - Ferrara University
 
Understanding System Performance
Understanding System PerformanceUnderstanding System Performance
Understanding System Performance
 
Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1Triad 2010 excel_chapter_1
Triad 2010 excel_chapter_1
 
SQL Server 2016 new features
SQL Server 2016 new featuresSQL Server 2016 new features
SQL Server 2016 new features
 
Obiee11g working with partitions
Obiee11g working with partitionsObiee11g working with partitions
Obiee11g working with partitions
 
Learn SAS Programming
Learn SAS ProgrammingLearn SAS Programming
Learn SAS Programming
 

Viewers also liked

Showdown: IBM DB2 versus Oracle Database for OLTP
Showdown: IBM DB2 versus Oracle Database for OLTPShowdown: IBM DB2 versus Oracle Database for OLTP
Showdown: IBM DB2 versus Oracle Database for OLTPcomahony
 
Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Antonios Chatzipavlis
 
Business Case: IBM DB2 versus Oracle Database - Conor O'Mahony
Business Case: IBM DB2 versus Oracle Database - Conor O'MahonyBusiness Case: IBM DB2 versus Oracle Database - Conor O'Mahony
Business Case: IBM DB2 versus Oracle Database - Conor O'Mahonycomahony
 
Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlAbDul ThaYyal
 
Intranet query tuning (example)
Intranet query tuning (example)Intranet query tuning (example)
Intranet query tuning (example)중선 곽
 
Grant Fritchey - Query Tuning In Azure SQL Database
Grant Fritchey - Query Tuning In Azure SQL DatabaseGrant Fritchey - Query Tuning In Azure SQL Database
Grant Fritchey - Query Tuning In Azure SQL DatabaseRed Gate Software
 
Query Tuning Azure SQL Databases
Query Tuning Azure SQL DatabasesQuery Tuning Azure SQL Databases
Query Tuning Azure SQL DatabasesGrant Fritchey
 
Microsoft SQL Server Query Tuning
Microsoft SQL Server Query TuningMicrosoft SQL Server Query Tuning
Microsoft SQL Server Query TuningMark Ginnebaugh
 
Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009mattsmiley
 
SQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First TimeSQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First TimeDean Richards
 
Oracle Query Tuning Tips - Get it Right the First Time
Oracle Query Tuning Tips - Get it Right the First TimeOracle Query Tuning Tips - Get it Right the First Time
Oracle Query Tuning Tips - Get it Right the First TimeDean Richards
 
Redshift performance tuning
Redshift performance tuningRedshift performance tuning
Redshift performance tuningCarlos del Cacho
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Developmentrehaniltifat
 
تحلیل احساسات در شبکه های اجتماعی
تحلیل احساسات در شبکه های اجتماعیتحلیل احساسات در شبکه های اجتماعی
تحلیل احساسات در شبکه های اجتماعیHamed Azizi
 
05 Creating Stored Procedures
05 Creating Stored Procedures05 Creating Stored Procedures
05 Creating Stored Proceduresrehaniltifat
 
Oracle SQL Performance Tuning and Optimization v26 chapter 1
Oracle SQL Performance Tuning and Optimization v26 chapter 1Oracle SQL Performance Tuning and Optimization v26 chapter 1
Oracle SQL Performance Tuning and Optimization v26 chapter 1Kevin Meade
 
Scientific Research Steps Part 1
Scientific Research Steps Part 1Scientific Research Steps Part 1
Scientific Research Steps Part 1Ainul Yaqin
 
Transcript of Presentation(Simple & Compound Interest) for Audience
Transcript of Presentation(Simple & Compound Interest) for AudienceTranscript of Presentation(Simple & Compound Interest) for Audience
Transcript of Presentation(Simple & Compound Interest) for Audiencerehaniltifat
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning晓 周
 

Viewers also liked (20)

Showdown: IBM DB2 versus Oracle Database for OLTP
Showdown: IBM DB2 versus Oracle Database for OLTPShowdown: IBM DB2 versus Oracle Database for OLTP
Showdown: IBM DB2 versus Oracle Database for OLTP
 
Ibm db2 case study
Ibm db2 case studyIbm db2 case study
Ibm db2 case study
 
Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)
 
Business Case: IBM DB2 versus Oracle Database - Conor O'Mahony
Business Case: IBM DB2 versus Oracle Database - Conor O'MahonyBusiness Case: IBM DB2 versus Oracle Database - Conor O'Mahony
Business Case: IBM DB2 versus Oracle Database - Conor O'Mahony
 
Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency control
 
Intranet query tuning (example)
Intranet query tuning (example)Intranet query tuning (example)
Intranet query tuning (example)
 
Grant Fritchey - Query Tuning In Azure SQL Database
Grant Fritchey - Query Tuning In Azure SQL DatabaseGrant Fritchey - Query Tuning In Azure SQL Database
Grant Fritchey - Query Tuning In Azure SQL Database
 
Query Tuning Azure SQL Databases
Query Tuning Azure SQL DatabasesQuery Tuning Azure SQL Databases
Query Tuning Azure SQL Databases
 
Microsoft SQL Server Query Tuning
Microsoft SQL Server Query TuningMicrosoft SQL Server Query Tuning
Microsoft SQL Server Query Tuning
 
Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009
 
SQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First TimeSQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First Time
 
Oracle Query Tuning Tips - Get it Right the First Time
Oracle Query Tuning Tips - Get it Right the First TimeOracle Query Tuning Tips - Get it Right the First Time
Oracle Query Tuning Tips - Get it Right the First Time
 
Redshift performance tuning
Redshift performance tuningRedshift performance tuning
Redshift performance tuning
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development
 
تحلیل احساسات در شبکه های اجتماعی
تحلیل احساسات در شبکه های اجتماعیتحلیل احساسات در شبکه های اجتماعی
تحلیل احساسات در شبکه های اجتماعی
 
05 Creating Stored Procedures
05 Creating Stored Procedures05 Creating Stored Procedures
05 Creating Stored Procedures
 
Oracle SQL Performance Tuning and Optimization v26 chapter 1
Oracle SQL Performance Tuning and Optimization v26 chapter 1Oracle SQL Performance Tuning and Optimization v26 chapter 1
Oracle SQL Performance Tuning and Optimization v26 chapter 1
 
Scientific Research Steps Part 1
Scientific Research Steps Part 1Scientific Research Steps Part 1
Scientific Research Steps Part 1
 
Transcript of Presentation(Simple & Compound Interest) for Audience
Transcript of Presentation(Simple & Compound Interest) for AudienceTranscript of Presentation(Simple & Compound Interest) for Audience
Transcript of Presentation(Simple & Compound Interest) for Audience
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning
 

Similar to Tips for Database Performance

Crucial Tips to Improve MySQL Database Performance.pptx
Crucial Tips to Improve MySQL Database Performance.pptxCrucial Tips to Improve MySQL Database Performance.pptx
Crucial Tips to Improve MySQL Database Performance.pptxTosska Technology
 
Building scalable application with sql server
Building scalable application with sql serverBuilding scalable application with sql server
Building scalable application with sql serverChris Adkin
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
Optimize access
Optimize accessOptimize access
Optimize accessAla Esmail
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMahesh Salaria
 
Sql interview question part 5
Sql interview question part 5Sql interview question part 5
Sql interview question part 5kaashiv1
 
Data Warehouse Best Practices
Data Warehouse Best PracticesData Warehouse Best Practices
Data Warehouse Best PracticesEduardo Castro
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09guest9d79e073
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Mark Ginnebaugh
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008paulguerin
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsDave Stokes
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-dbuncleRhyme
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesJavier García Magna
 
The thinking persons guide to data warehouse design
The thinking persons guide to data warehouse designThe thinking persons guide to data warehouse design
The thinking persons guide to data warehouse designCalpont
 

Similar to Tips for Database Performance (20)

Teradata sql-tuning-top-10
Teradata sql-tuning-top-10Teradata sql-tuning-top-10
Teradata sql-tuning-top-10
 
Crucial Tips to Improve MySQL Database Performance.pptx
Crucial Tips to Improve MySQL Database Performance.pptxCrucial Tips to Improve MySQL Database Performance.pptx
Crucial Tips to Improve MySQL Database Performance.pptx
 
Building scalable application with sql server
Building scalable application with sql serverBuilding scalable application with sql server
Building scalable application with sql server
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
Optimize access
Optimize accessOptimize access
Optimize access
 
Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source Database
 
Ebook5
Ebook5Ebook5
Ebook5
 
Sql interview question part 5
Sql interview question part 5Sql interview question part 5
Sql interview question part 5
 
Data Warehouse Best Practices
Data Warehouse Best PracticesData Warehouse Best Practices
Data Warehouse Best Practices
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Speed up sql
Speed up sqlSpeed up sql
Speed up sql
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
Sql good practices
Sql good practicesSql good practices
Sql good practices
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelines
 
The thinking persons guide to data warehouse design
The thinking persons guide to data warehouse designThe thinking persons guide to data warehouse design
The thinking persons guide to data warehouse design
 
Ebook11
Ebook11Ebook11
Ebook11
 

More from Kesavan Munuswamy

Surviving Migration To Office 365 an it pros guide ebook
Surviving Migration To Office 365 an it pros guide ebookSurviving Migration To Office 365 an it pros guide ebook
Surviving Migration To Office 365 an it pros guide ebookKesavan Munuswamy
 
Windows_Server_2016_Virtualization White Paper By Veeam
Windows_Server_2016_Virtualization White Paper By VeeamWindows_Server_2016_Virtualization White Paper By Veeam
Windows_Server_2016_Virtualization White Paper By VeeamKesavan Munuswamy
 
MSFT Cloud Architecture Information Protection
MSFT Cloud Architecture Information ProtectionMSFT Cloud Architecture Information Protection
MSFT Cloud Architecture Information ProtectionKesavan Munuswamy
 
Ms cloud identity and access infographic 2015
Ms cloud identity and access infographic 2015Ms cloud identity and access infographic 2015
Ms cloud identity and access infographic 2015Kesavan Munuswamy
 
Ms cloud design patterns infographic 2015
Ms cloud design patterns infographic 2015Ms cloud design patterns infographic 2015
Ms cloud design patterns infographic 2015Kesavan Munuswamy
 
Microsoft azure infographic 2015 2.5
Microsoft azure infographic 2015 2.5Microsoft azure infographic 2015 2.5
Microsoft azure infographic 2015 2.5Kesavan Munuswamy
 
Cloud Design Patterns Book from Microsoft
Cloud Design Patterns Book from MicrosoftCloud Design Patterns Book from Microsoft
Cloud Design Patterns Book from MicrosoftKesavan Munuswamy
 
Azure security infographic 2014 sec
Azure security infographic 2014 secAzure security infographic 2014 sec
Azure security infographic 2014 secKesavan Munuswamy
 
Windows Server 2012 Exam Paper 70-411 PDF
Windows Server 2012 Exam Paper 70-411 PDFWindows Server 2012 Exam Paper 70-411 PDF
Windows Server 2012 Exam Paper 70-411 PDFKesavan Munuswamy
 
MCSA Server 2012 Exam Paper 1- Ms 70 410
MCSA Server 2012  Exam Paper 1- Ms 70 410MCSA Server 2012  Exam Paper 1- Ms 70 410
MCSA Server 2012 Exam Paper 1- Ms 70 410Kesavan Munuswamy
 
Inside the sql server query optimizer
Inside the sql server query optimizer Inside the sql server query optimizer
Inside the sql server query optimizer Kesavan Munuswamy
 
Step by Step Windows Azure pack for windows server 2012 R2 Guide v1
Step by Step Windows Azure pack for windows server 2012 R2 Guide v1Step by Step Windows Azure pack for windows server 2012 R2 Guide v1
Step by Step Windows Azure pack for windows server 2012 R2 Guide v1Kesavan Munuswamy
 
SQL Server Source Control Basics
SQL Server Source Control BasicsSQL Server Source Control Basics
SQL Server Source Control BasicsKesavan Munuswamy
 
Fundamentals of sql server 2012 replication e book
Fundamentals of sql server 2012 replication e bookFundamentals of sql server 2012 replication e book
Fundamentals of sql server 2012 replication e bookKesavan Munuswamy
 
SQL Server Backup and Restore
SQL Server Backup and RestoreSQL Server Backup and Restore
SQL Server Backup and RestoreKesavan Munuswamy
 
Extending Role Security in Analysis Services for SQL Server
Extending Role Security in Analysis Services for SQL ServerExtending Role Security in Analysis Services for SQL Server
Extending Role Security in Analysis Services for SQL ServerKesavan Munuswamy
 
SQL High Availability solutions E Book
SQL High Availability solutions E BookSQL High Availability solutions E Book
SQL High Availability solutions E BookKesavan Munuswamy
 

More from Kesavan Munuswamy (18)

Surviving Migration To Office 365 an it pros guide ebook
Surviving Migration To Office 365 an it pros guide ebookSurviving Migration To Office 365 an it pros guide ebook
Surviving Migration To Office 365 an it pros guide ebook
 
Windows_Server_2016_Virtualization White Paper By Veeam
Windows_Server_2016_Virtualization White Paper By VeeamWindows_Server_2016_Virtualization White Paper By Veeam
Windows_Server_2016_Virtualization White Paper By Veeam
 
MSFT Cloud Architecture Information Protection
MSFT Cloud Architecture Information ProtectionMSFT Cloud Architecture Information Protection
MSFT Cloud Architecture Information Protection
 
Ms cloud identity and access infographic 2015
Ms cloud identity and access infographic 2015Ms cloud identity and access infographic 2015
Ms cloud identity and access infographic 2015
 
Ms cloud design patterns infographic 2015
Ms cloud design patterns infographic 2015Ms cloud design patterns infographic 2015
Ms cloud design patterns infographic 2015
 
Microsoft azure infographic 2015 2.5
Microsoft azure infographic 2015 2.5Microsoft azure infographic 2015 2.5
Microsoft azure infographic 2015 2.5
 
Cloud Design Patterns Book from Microsoft
Cloud Design Patterns Book from MicrosoftCloud Design Patterns Book from Microsoft
Cloud Design Patterns Book from Microsoft
 
Azure security infographic 2014 sec
Azure security infographic 2014 secAzure security infographic 2014 sec
Azure security infographic 2014 sec
 
MCSA Exam paper 70-412 PDF
MCSA Exam paper 70-412 PDFMCSA Exam paper 70-412 PDF
MCSA Exam paper 70-412 PDF
 
Windows Server 2012 Exam Paper 70-411 PDF
Windows Server 2012 Exam Paper 70-411 PDFWindows Server 2012 Exam Paper 70-411 PDF
Windows Server 2012 Exam Paper 70-411 PDF
 
MCSA Server 2012 Exam Paper 1- Ms 70 410
MCSA Server 2012  Exam Paper 1- Ms 70 410MCSA Server 2012  Exam Paper 1- Ms 70 410
MCSA Server 2012 Exam Paper 1- Ms 70 410
 
Inside the sql server query optimizer
Inside the sql server query optimizer Inside the sql server query optimizer
Inside the sql server query optimizer
 
Step by Step Windows Azure pack for windows server 2012 R2 Guide v1
Step by Step Windows Azure pack for windows server 2012 R2 Guide v1Step by Step Windows Azure pack for windows server 2012 R2 Guide v1
Step by Step Windows Azure pack for windows server 2012 R2 Guide v1
 
SQL Server Source Control Basics
SQL Server Source Control BasicsSQL Server Source Control Basics
SQL Server Source Control Basics
 
Fundamentals of sql server 2012 replication e book
Fundamentals of sql server 2012 replication e bookFundamentals of sql server 2012 replication e book
Fundamentals of sql server 2012 replication e book
 
SQL Server Backup and Restore
SQL Server Backup and RestoreSQL Server Backup and Restore
SQL Server Backup and Restore
 
Extending Role Security in Analysis Services for SQL Server
Extending Role Security in Analysis Services for SQL ServerExtending Role Security in Analysis Services for SQL Server
Extending Role Security in Analysis Services for SQL Server
 
SQL High Availability solutions E Book
SQL High Availability solutions E BookSQL High Availability solutions E Book
SQL High Availability solutions E Book
 

Recently uploaded

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 

Recently uploaded (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 

Tips for Database Performance

  • 1. 1
  • 2. 2 PHIL FACTOR GRANT FRITCHEY K. BRIAN KELLEY MICKEY STUEWE IKE ELLIS JONATHAN ALLEN LOUIS DAVIDSON
  • 3. Database Performance Tips for Developers As a developer, you may or may not need to go into the database and write queries, or design tables and indexes, or help determine configuration of your SQL Server systems. But if you do, these tips should help to make that a more pain free process.
  • 4. 4 Contents Tips 1-5 ORM Tips Tips 6-24 T-SQL Tips Tips 25-40 Index Tips Tips 41-45 Database Design Tips 5 7 12 17
  • 5. 5 ORM Tips More and more people are using Object to Relational Mapping (ORM) tools to jump the divide between application code that is object oriented and a database that stores information in a relational manner. These tools are excellent and radically improve development speed, but there are a few ‘gotchas’ to know about. 1 Avoid following the ‘Hello World’ examples provided with your ORM tool that turns it into an Object to Object Mapping. Database storage is not the same as objects for a reason. You should still have a relational storage design within a relational storage engine such as SQL Server. Parameterized queries are exactly the same as stored procedures in terms of performance and memory management. Since most ORM tools can use either stored procedures or parameterized queries, be sure you’re coding to these constructs and not hard-coding values into your T-SQL queries. 2
  • 6. 6 Create, Read, Update, and Delete (CRUD) queries can all be generated from the ORM tool without the need for intervention. But, the Read queries generated are frequently very inefficient. Consider writing a stored procedure for complex Read queries. Since the code generated from the ORM can frequently be ad hoc, ensure that the SQL Server instance has ‘Optimize for Ad Hoc’ enabled. This will store a plan stub in memory the first time a query is passed, rather than storing a full plan. This can help with memory management. Be sure your code is generating a parameter size equivalent to the data type defined within the table in the database. Some ORM tools size the parameter to the size of the value passed. This can lead to serious performance problems. 3 4 5
  • 7. 7 T-SQL Tips While much of your code may be generated, at least some of it will have to be written by hand. If you are writing some or all of your T-SQL code, these tips will help you avoid problems. SELECT * is not always a bad thing, but it’s a good idea to only move the data you really need to move and only when you really need it, in order to avoid network, disk, and memory contention on your server. Keep transactions as short as possible and never use them unnecessarily. The longer a lock is held the more likely it is that another user will be blocked. Never hold a transaction open after control is passed back to the application – use optimistic locking instead. 6 7 For small sets of data that are infrequently updated such as lookup values, build a method of caching them in memory on your application server rather than constantly querying them in the database. 8
  • 8. 8 If doing processing within a transaction, leave the updates until last if possible, to minimize the need for exclusive locks. Cursors within SQL Server can cause severe performance bottlenecks. Avoid them. The WHILE loop within SQL Server is just as bad as a cursor. Ensure your variables and parameters are the same data types as the columns. An implicit or explicit conversion can lead to table scans and slow performance. 9 10 11 A function on columns in the WHERE clause or JOIN criteria means that SQL Server can’t use indexes appropriately and will lead to table scans and slow performance. 12
  • 9. 9 Don’t use DISTINCT, ORDER BY, or UNION unnecessarily. Table variables have no statistics within SQL Server. This makes them useful for working in situations where a statement level recompile can slow performance. But, that lack of statistics makes them very inefficient where you need to do searches or joins. Use table variables only where appropriate. 13 14 Multi-statement user-defined functions work through table variables. Because of this, they also don’t work well in situations where statistics are required. If a join or filtering is required, avoid using them, especially if you are working with more than approximately 50 rows in the data set. 15
  • 10. 10 Query hints are actually commands to the query optimizer to control how a query plan is generated. These should be used very sparingly and only where appropriate. One of the most abused query hints is NO_LOCK. This can lead to extra or missing rows in data sets. Instead of using NO_LOCK consider using a snapshot isolation level such as READ_COMMITTED_SNAPSHOT. 16 17 Avoid creating stored procedures that have a wide range of data supplied to them as parameters. These are compiled to use just one query plan. 18 Try not to interleave data definition language with your data manipulation language queries within SQL Server. This can lead to recompiles which hurts performance. 19 Temporary tables have statistics which get updated as data is inserted into them. As these updates occur, you can get recompiles. Where possible, substitute table variables to avoid this issue. 20
  • 11. 11 If possible, avoid NULL values in your database. If not, use the appropriate IS NULL and IS NOT NULL code. 21 A view is meant to mask or modify how tables are presented to the end user. These are fine constructs. But when you start joining one view to another or nesting views within views, performance will suffer. Refer only to tables within a view. 22 Use extended events to monitor the queries in your system in order to identify slow running queries. If you’re on a 2005 or earlier system you’ll need to use a server-side trace. 24 If you need to insert many rows at once into a table, use, where possible, the multi-row VALUES clause in INSERT statements. 23
  • 12. 12 Index Tips Indexing tables is not an exact science. It requires some trial and error combined with lots of testing to get things just right. Even then, the performance metrics will change over time as you add more and more data. You get exactly one clustered index on a table. Ensure you have it in the right place. First choice is the most frequently accessed column, which may or may not be the primary key. Second choice is a column that structures the storage in a way that helps performance. This is a must for partitioning data. Clustered indexes work well on columns that are used a lot for ‘range’ WHERE clauses such as BETWEEN and LIKE, where it is frequently used in ORDER BY clauses or in GROUP BY clauses. 25 26
  • 13. 13 If clustered indexes are narrow (involve few columns) then this will mean that less storage is needed for non-clustered indexes for that table. You do not have to make the primary key the clustered index. This is default behavior but can be directly controlled. You should have a clustered index on every table in the database. There are exceptions, but the exceptions should be exceptional. 27 28 29 Avoid using a column in a clustered index that has values that are frequently updated. 30
  • 14. 14 Only create non-clustered indexes on tables when you know they’ll be used through testing. You can seriously hurt performance by creating too many indexes on a table. Keep your indexes as narrow as possible. This means reducing the number and size of the columns used in the index key. This helps make the index more efficient. 31 32 Always index your foreign key columns if you are likely to delete rows from the referenced table. This avoids a table scan. 33
  • 15. 15 A clustered index on a GUID can lead to serious fragmentation of the index due to the random nature of the GUID. You can use the function NEWSEQUENTIALID() to generate a GUID that will not lead to as much fragmentation. Performance is enhanced when indexes are placed on columns used in WHERE, JOIN, ORDER BY, GROUP, and TOP. Always test to ensure that the index does help performance. 34 35 If a non-clustered index is useful to your queries, but doesn’t have all the columns needed by the query, you can consider using the INCLUDE option to store the extra columns at the leaf level of the index. 36
  • 16. 16 If temporary tables are in use, you can add indexes to those tables to enhance their performance. Where possible, make the indexes unique. This is especially true of the clustered index (one of the reasons that the primary key is by default clustered). A unique index absolutely performs faster than a non-unique index, even with the same values. 37 38 Ensure that the selectivity of the data in the indexes is high. Very few unique values makes an index much less likely to be used well by the query optimizer. It is almost always better to let SQL Server update statistics automatically. 39 40
  • 17. 17 Database Design Tips Again, you may not be delving much into this, but there are a few tips to keep in mind. While it is possible to over-normalize a database, under-normalization is much more prevalent. This leads to repetition of data, inefficient storage, and poor performance. Data normalization is a performance tuning technique as well as a storage mechanism. Referential integrity constraints such as foreign keys actually help performance, because the optimizer can recognize these enforced constraints and make better choices for joins and other data access. 41 42
  • 18. 18 Make sure your database doesn’t hold ‘historic’ data that is no longer used. Archive it out, either into a special ‘archive’ database, a reporting OLAP database, or on file. Large tables mean longer table scans and deeper indexes. This in turn can mean that locks are held for longer. Admin tasks such as Statistics updates, DBCC checks, and index builds take longer, as do backups. Separate out the reporting functions from the OLTP production functions. OLTP databases usually have short transactions with a lot of updates whereas reporting databases, such as OLAP and data warehouse systems, have longer data-heavy queries. If possible, put them on different servers. 44 45 Unique constraints also help performance because the optimizer can use these in different ways to enhance its query tuning. 43
  • 19. 19 Tools SQL Prompt Write, refactor, and explore SQL effortlessly with this SQL Server Management Studio plug-in. SQL Compare Compare database schemas and deploy database schema changes. SQL Source Control Connect your databases to your version control system within SQL Server Management Studio. SQL Backup Pro Schedule backup jobs, verify with DBCC CHECKDB, and compress backups by up to 95%. SQL Index Manager Analyze, manage, and fix database index fragmentation.
  • 20. 20 Books SQL Server Execution Plans by Grant Fritchey Learn the basics of capturing plans, how to interrupt them in their various forms, graphical or XML, and then how to use the information you find. Diagnose the most common causes of poor query performance so you can optimize your SQL queries and improve your indexing strategy. SQL Server Concurrency: Locking, Blocking and Row Versioning by Kalen Delaney Your application can have world-class indexes and queries, but they won’t help you if you can’t get your data because another application has it locked. That’s why every DBA and developer must understand SQL Server concurrency, and how to troubleshoot any issues. SQL Server Transaction Log Management by Tony Davis and Gail Shaw Tony Davis and Gail Shaw strive to offer just the right level of detail so that every DBA can perform all of the most important aspects of transaction log management.
  • 21. 21 Troubleshooting SQL Server: A Guide for the Accidental DBA by Jonathan Kehayias and Ted Krueger Three SQL Server MVPs provide fascinating insight into the most common SQL Server problems, why they occur, and how they can be diagnosed using tools such as Performance Monitor, Dynamic Management Views, and server-side tracing performance, so you can optimize your SQL queries and improve your indexing strategy. Defensive Database Programming by Alex Kuznetsov The goal of defensive database programming is to help you to produce resilient T-SQL code that robustly and gracefully handles cases of unintended use, and is resilient to common changes to the database environment.