The Complete Guide to Temporary Tables and Table Variables

Slides:



Advertisements
Similar presentations
How SAS implements structured programming constructs
Advertisements

IGOR: A System for Program Debugging via Reversible Execution Stuart I. Feldman Channing B. Brown slides made by Qing Zhang.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
XVII Encontro – 29/11/2011. Virgílio Esteves ID&T – Research & Founder of NetPonto Coimbra C# / WPF / Silverlight / XNA / Azure.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Excel 2010 by Robert Grauer, Keith.
Chap 8-1 Copyright ©2013 Pearson Education, Inc. publishing as Prentice Hall Chapter 8 Confidence Interval Estimation Business Statistics: A First Course.
4 Copyright © 2006, Oracle. All rights reserved. Recovering from Noncritical Losses.
Understanding SSIS Control Flows Bret Stateham Training Manager Vortex Learning Solutions blogs.netconnex.com.
“Participant-Centered Training” Bob Pike Annual Conference September 12-14, 2012 Minneapolis, MN.
DB2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/DB01/003 Version No:2.0a Session Plan Introduction to Concurrency Control Different types.
D Copyright © Oracle Corporation, All rights reserved. Loading Data into a Database.
SeETL Demonstration 22 Data Modelling 20/07/2013
How to Use Parameters Like a Pro …and Boost Performance Guy Glantser, CEO, Madeira.
Copyright © Andrew Couch 2007 All rights reserved. Access Tables Without Keys & Views How To Manage Keys On Access Tables Andrew Couch ASC Associates.
Meta Data Cardinality Explored CSSQLUG User Group - June 2009.
Part-time Jobs. What’s the difference between part-time jobs in the West and China?
Homes. Most homes in the West are houses. Almost all Westerners have to get a mortgage to buy a home. There are also property taxes. Image courtesy of.
Work. Think of and write down at least five jobs that you might like to have.
3 Copyright © 2004, Oracle. All rights reserved. Database Architecture Comparison.
Bret Stateham Owner, Net Connex blogs.netconnex.com
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
Making a Difference with Azure Storage Solutions Dudu Sinai.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information.
SQL Server Magic Buttons! What are Trace Flags and why should I care? Steinar Andersen, SQL Service Nordic AB Thanks to Thomas Kejser for peer-reviewing.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
The HDF Group Introduction to HDF5 Session ? High Performance I/O 1 Copyright © 2010 The HDF Group. All Rights Reserved.
Part-time Jobs. What’s the difference between part-time jobs and temporary jobs?
The Need for Algorithms
Stored Procedures – Facts and Myths
Antonio Abalos Castillo
Things You Can Find in the Plan Cache.
SHARED MEMORY PROGRAMMING WITH OpenMP
General Systems Enhancements
The Simplex Method The geometric method of solving linear programming problems presented before. The graphical method is useful only for problems involving.
# - it’s not about social media it’s about temporary tables and data
# - it’s not about social media it’s about temporary tables and data
Optimizing Microsoft SQL Server 2008 Applications Using Table Valued Parameters, XML, and MERGE
Working with Very Large Tables Like a Pro in SQL Server 2014
Decoding the Cardinality Estimator to Speed Up Queries
Now where does THAT estimate come from?
Cardinality Estimator 2014/2016
Statistics What are the chances
Query Optimization Techniques
Top Tips for Better TSQL Stored Procedures
PT2520 Unit 9: Database Security II
C Programming APP3o.
Statistics: What are they and How do I use them
Mean.
When query plans go wrong
Relations in Categorical Data
TEMPDB – INTERNALS AND USAGE
Hugo Kornelis Now where does THAT estimate come from? The nuts and bolts of cardinality estimation.
How to Use Parameters Like a Pro
T-SQL gotchas and power-ups
Parameter Sniffing: the Good, the Bad, and the Ugly
Parameter Sniffing: the Good,the Bad, and the Ugly
Section 4-3 Relations in Categorical Data
Parameter Sniffing: the Good, the Bad, and the Ugly
Chapter 11 Managing Databases with SQL Server 2000
SQL Server Query Design and Optimization Recommendations
Query Optimization Techniques
The Complete Guide to Temporary Tables and Table Variables
Units – Powers to Prefix (4)
Units – Powers to Prefix (1)
Units – Powers to Prefix (2)
Using wait stats to determine why my server is slow
Working with Very Large Tables Like a Pro in SQL Server 2017
Units – Powers to Prefix (3)
Analyzing Execution Plans
Presentation transcript:

The Complete Guide to Temporary Tables and Table Variables Guy Glantser

Copyright © 2019 Madeira Ltd All Rights Reserved Full rights, including copyrights, belong exclusively to Madeira Ltd No use of the materials, in any form, is allowed, unless receiving a prior written permission from Madeira Ltd

A Few Words about Me… Name: Guy Glantser Email Address: guy@madeiradata.com Twitter: @guy_glantser Blog: www.linkedin.com/in/glantser Podcast: www.sqlserverradio.com Image courtesy of Mister GC / FreeDigitalPhotos.net

First, a Basic Comparison… Temporary Table Table Variable Storage tempdb Scope Session Batch Constraints Yes

First, a Basic Comparison… Temporary Table Table Variable Indexes Yes Statistics Yes No Recompilations Yes No

First, a Basic Comparison… Temporary Table Table Variable T-Log Footprint Full Minimal Table Parameters No Yes Parallelism Yes No

The Big Question: When to Use What?

Image courtesy of Stuart Miles / FreeDigitalPhotos.net

Bottom Line If the batch is executed only once in a while Use a temporary table with OPTION (RECOMPILE)

Bottom Line If not (the batch is executed many times per second) If the number of rows in the table is relatively fixed Use a temporary table

Bottom Line If the number of rows in the table varies all the time If performance with a temporary table is acceptable (due to recompiles) Use a temporary table

Bottom Line If performance with a temporary table is not acceptable If performance with a table variable is acceptable Use a table variable

Bottom Line If performance is not acceptable either way Try a hybrid solution

Bottom Line When using a table-valued parameter Consider using trace flag 2453

Image courtesy of David Castillo Dominici / FreeDigitalPhotos.net

Keep in Touch… Name: Guy Glantser Email Address: guy@madeiradata.com Twitter: @guy_glantser Blog: www.linkedin.com/in/glantser Podcast: www.sqlserverradio.com Image courtesy of Mister GC / FreeDigitalPhotos.net