Download presentation
Presentation is loading. Please wait.
Published byMiriam Schenck Modified over 5 years ago
1
The Complete Guide to Temporary Tables and Table Variables
Guy Glantser
2
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
3
A Few Words about Me… Name: Guy Glantser
Address: Blog: Podcast: Image courtesy of Mister GC / FreeDigitalPhotos.net
5
First, a Basic Comparison…
Temporary Table Table Variable Storage tempdb Scope Session Batch Constraints Yes
6
First, a Basic Comparison…
Temporary Table Table Variable Indexes Yes Statistics Yes No Recompilations Yes No
7
First, a Basic Comparison…
Temporary Table Table Variable T-Log Footprint Full Minimal Table Parameters No Yes Parallelism Yes No
8
The Big Question: When to Use What?
9
Image courtesy of Stuart Miles / FreeDigitalPhotos.net
10
Bottom Line If the batch is executed only once in a while
Use a temporary table with OPTION (RECOMPILE)
11
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
12
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
13
Bottom Line If performance with a temporary table is not acceptable
If performance with a table variable is acceptable Use a table variable
14
Bottom Line If performance is not acceptable either way
Try a hybrid solution
15
Bottom Line When using a table-valued parameter
Consider using trace flag 2453
16
Image courtesy of David Castillo Dominici / FreeDigitalPhotos.net
17
Keep in Touch… Name: Guy Glantser Email Address: guy@madeiradata.com
Blog: Podcast: Image courtesy of Mister GC / FreeDigitalPhotos.net
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.