TSQL Worst Practices “What did I do?”Pinal DaveTechnology Evangelist
Agenda• TSQL Worst Practices  – TSQL Usages that kills performance  – TSQL Usages that produce unexpected results         ...
Using NOT IN()• Use NOT EXISTS() instead of NOT IN()• When using NOT IN() be careful for NULL  values                     ...
COUNT() with LEFT JOIN• COUNT(*) with LEFT JOIN may produce  incorrect results• Use COUNT(column) from RIGHT side table  i...
Using Incorrect Data Type• Incorrect data types in WHERE clause causes  TABLE SCAN due to implicit conversion             ...
Functions in WHERE Clause• Functions around columns in a WHERE clause  causes TABLE SCAN                                  ...
ORDER BY with Ordinal Position• Avoid using ordinal position in ORDER BY• If an ordinal position is specified in an  expre...
SET XACT_ABORT ON• SET XACT_ABORT ON in stored procedures to  rollback open transactions in case of  unhandled errors     ...
Take AwayBe Good Developer                    9
Upcoming SlideShare
Loading in …5
×

“What did I do?” - T-SQL Worst Practices

880 views

Published on

“Oh My God! What did I do?” Chances are you have heard, or even uttered, this expression. This demo-oriented session will have many examples where developers were dumbfounded by their own mistakes. The goal of this session is to learn which small details can be dangerous to the production environment and SQL Server as a whole. We will talk about common bad habits and how to avoid them. There is good chance you will remember your early days during the session. Learning some of these tricks may save your current job.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
880
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

“What did I do?” - T-SQL Worst Practices

  1. 1. TSQL Worst Practices “What did I do?”Pinal DaveTechnology Evangelist
  2. 2. Agenda• TSQL Worst Practices – TSQL Usages that kills performance – TSQL Usages that produce unexpected results 2
  3. 3. Using NOT IN()• Use NOT EXISTS() instead of NOT IN()• When using NOT IN() be careful for NULL values 3
  4. 4. COUNT() with LEFT JOIN• COUNT(*) with LEFT JOIN may produce incorrect results• Use COUNT(column) from RIGHT side table instead of COUNT(*) 4
  5. 5. Using Incorrect Data Type• Incorrect data types in WHERE clause causes TABLE SCAN due to implicit conversion 5
  6. 6. Functions in WHERE Clause• Functions around columns in a WHERE clause causes TABLE SCAN 6
  7. 7. ORDER BY with Ordinal Position• Avoid using ordinal position in ORDER BY• If an ordinal position is specified in an expression, it may not produce the expected results• If an expression is used in ORDER BY, it will be evaluated when FILTERS are evaluated 7
  8. 8. SET XACT_ABORT ON• SET XACT_ABORT ON in stored procedures to rollback open transactions in case of unhandled errors 8
  9. 9. Take AwayBe Good Developer 9

×