TSQL Coding Techniques

Slides:



Advertisements
Similar presentations
Extended Director’s Cut Like you’ve never seen it before In Widescreen Hi-Definition Blu-Ray In 3D With Director’s commentary In 7.1 Surround Sound In.
Advertisements

Dave Ballantyne Clear Sky SQL. ›Freelance Database Developer/Designer –Specializing in SQL Server for 15+ years ›SQLLunch –Lunchtime usergroup –London.
Confidence Intervals for Proportions
Copyright © 2010 Pearson Education, Inc. Chapter 19 Confidence Intervals for Proportions.
Overview SQL Server 2008 Overview Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP, MCTS Microsoft Web Development MCP ITIL.
T-SQL : Bad Habits to Kick Aaron Bertrand SQL Sentry, Inc.
SQL Spackle #1 Jeff Moden 19 May About Your Speaker Mostly Self Trained Started with SQL Server in 1995 More than 25,000 posts on SQLServerCentral.com.
SQL for SQL Server, C13© 2002, Mike Murach & Associates, Inc. Slide 1.
Copyright © 2009 Pearson Education, Inc. Chapter 19 Confidence Intervals for Proportions.
Stored Procedure Optimization Preventing SP Time Out Delay Deadlocking More DiskReads By: Nix.
Meta Data Cardinality Explored CSSQLUG User Group - June 2009.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
RETRIEVE A NO. OF ROWS ¦ Declare a cursor ¦ Open the cursor ¦ Fetch rows of data ¦ Stop fetching rows ¦ Close the cursor.
Module 9: Using Advanced Techniques. Considerations for Querying Data Working with Data Types Cursors and Set-Based Queries Dynamic SQL Maintaining Query.
TSQL Worst Practices Jacob Sebastian, SQL Server MVP
How to kill SQL Server Performance Håkan Winther.
1 Section 10 - Embedded SQL u Many computer languages allow you to embed SQL statements within the code (e.g. COBOL, PowerBuilder, C++, PL/SQL, etc.) u.
Dynamic SQL Writing Efficient Queries on the Fly ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
High Performance Functions SQLBits VI. Going backwards is faster than going forwards.
Impostor Sydrome Are You Faking it, and Will They Find Out? Mindy Curnutt TMW Systems / Trimble Navigation.
3 Methods to End the Madness
Confidence Intervals for Proportions
Parameter Sniffing in SQL Server Stored Procedures
Fun with SQL Server Spatial Data
Query Optimization Techniques
Dynamic SQL Writing Efficient Queries on the Fly
Execution Planning for Success
Clearly Visual Basic: Programming with Visual Basic nd Edition
T-SQL Coding Techniques Are you playing with fire?
Understanding & Using Spatial Data Features in SQL Server
Using Extended Events to Diagnose Application Issues
Parameter Sniffing in SQL Server Stored Procedures
Confidence Intervals for Proportions
Confidence Intervals for Proportions
Dynamic SQL Writing Efficient Queries on the Fly
Error Handling Summary of the next few pages: Error Handling Cursors.
1Z0-148 Dumps Oracle Database 12c: Advanced PL/SQL Exam Just 1 day study required to pass exam 100% Passing Assurance.
Reading Execution Plans Successfully
Introduction to Execution Plans
The Ins and Outs of Indexes
The Ins and Outs of Indexes
Fun with SQL Server Spatial Data
Now where does THAT estimate come from?
Query Optimization Techniques
Top Tips for Better TSQL Stored Procedures
Indexing Fundamentals
The Ins and Outs of Indexes
Tally Ho! -- Explore the Varied Uses of Tally Tables
Indexing for Beginners
Transact SQL Performance Tips
Cursors Organized by Farrokh Alemi, Ph.D. Narrated by Yara Alemi
Parameter Sniffing: the Good, the Bad, and the Ugly
Four Rules For Columnstore Query Performance
Introduction to Execution Plans
Parameter Sniffing: the Good,the Bad, and the Ugly
Parameter Sniffing: the Good, the Bad, and the Ugly
Chapter 8 Advanced SQL.
Query Tuning Fundamentals
The Ins and Outs of Indexes
Confidence Intervals for Proportions
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
SQL Server Query Design and Optimization Recommendations
Introduction to Execution Plans
Arrays.
Query Optimization Techniques
Confidence Intervals for Proportions
Reading execution plans successfully
Introduction to Execution Plans
The Ins and Outs of Indexes
Presentation transcript:

TSQL Coding Techniques Are You Playing with Fire? Mindy Curnutt TMW Systems / Trimble Navigation

About Me Wife & Mother Busy-Bee Musician Soap Making Baking Crocheting Entrepreneur Event Planning

About Me VP, Information Management, TMW SQL Server MVP SQL Server since 6.5 / 1995 (20 Years) SQLPASS Speaker, 2005, 2012-2015 PASS Program Manager 2015 & 2016 Twitter: @sqlgirl Email: mindycurnutt@hotmail.com

Agenda Non-Set Based Approaches Scalar Functions Implicit Conversions Non Parameterized SQL Parameter Sniffing

Looping Cursors While Loops Scalar Functions For / Next…

Looping While Loops For / Next Do Until Cursors

How to Not Loop? Think COLUMN instead of ROW Change many rows with one statement

Scalar Functions Simplify your code Code Re-Use Great - under certain conditions Under the wrong conditions – can be deadly!

How to Use Scalar Functions Safely? ONLY in Select Clause and with a Small Result Set Do not reference tables Not in Where Clause!

Implicit Conversions Who wants to take the time to research and declare the correct data type? BORING “I tried to think of the most harmless thing. Something I loved from my childhood. Something that could never ever possibly destroy us.” Cursors While Loops For / Next…

How to Avoid Implicit Conversions Correctly define data types Match data types up Do not mix data of different types in tables Know your precision levels Watch the ORM code

Non Parameterized SQL I’ve got a plan. You’ve got a plan too? Hey, look at that, We’ve all got our own SEPARATE PLANS!

How to use Parameterization Do not concatenate SQL parameters as string values Learn how to use the parameter feature of sp_executeSQL

Parameter Sniffing What’s that first value you gave me? Great, I’ll make you the perfect execution plan for that! Next time, we don’t have to waste time figuring out a plan, we can use the one I have right here! Cursors While Loops For / Next…

How Parameter Sniffing can go awry Values within a column have very different distribution Column is naturally increasing at a high rate Statistics are not accurate Statistic sampling is not sufficient

Value Lists IN() CHARINDEX() Convert to a Table Variable and Join

High Performing Value Lists Convert value list into a Table Variable Submit value list as a Table Valued Parameter

Mindy Curnutt VP, Information Management, TMW Systems T H A N K Y O U Mindy Curnutt VP, Information Management, TMW Systems p: 440.721.2819 e: mcurnutt@tmwsystems.com t: @sqlgirl M O V I N G Y O U F O R W A R D