Download presentation
Presentation is loading. Please wait.
Published byEmil Porter Modified over 9 years ago
1
TSQL Worst Practices Jacob Sebastian, SQL Server MVP http://beyondrelational.com
2
Speaker Profile SQL Server MVP Author –The Art of XSD –The Art of FILESTREAM –SQL Server 2008 Bible co-author jacob@beyondrelational.com http://beyondrelational.com/blogs/jacob
3
Agenda Worst Practices –Not filling feed back form –Not giving a “9” –Falling asleep during the session –Leaving in the middle of the session –Not clapping when you like something
4
Agenda TSQL Worst Practices –TSQL Usages that kill performance –TSQL Usages that produce unexpected results
5
Demos
6
Using NOT IN() Use NOT EXISTS() instead of NOT IN() When using NOT IN() pay attention to NULL values
7
COUNT() with LEFT JOIN COUNT(*) with LEFT JOIN may produce incorrect results Use COUNT(column) from RIGHT side table instead of COUNT(*)
8
Using Incorrect data type Incorrect data types in WHERE clause causes implicit conversion and slow down queries Always use the correct data types in filters
9
Functions in WHERE clause Functions around columns in a WHERE clause is a performance killer Consider the possibility of TIME part when processing DATETIME values When converting a DATETIME column to DATE, an index on the column can still be used
10
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
11
SET XACT_ABORT ON SET XACT_ABORT ON in stored procedures to rollback open transactions in case of unhandled errors
12
Questions
13
Thank You! Email: jacob@beyondrelational.comjacob@beyondrelational.com Twitter: @jacobsebastian Blog: http://beyondrelational.com/blogs/jacobhttp://beyondrelational.com/blogs/jacob
14
Reminders Get Ready for the next session by Prem Mehra Do not miss Pinal Dave’s session on Friday
15
Resources Software Application Developers http://msdn.microsoft.com/ Infrastructure Professionals http://technet.microsoft.com/ msdnindia technetindia @msdnindia @technetindia
16
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.