Download presentation
Presentation is loading. Please wait.
Published byИрина Галкина Modified over 5 years ago
1
The Complete Guide to Temporary Tables and Table Variables
Guy Glantser
2
Copyright © 2018 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 tempdb Storage Session Batch Scope Yes Constraints
6
First, a Basic Comparison…
Temporary Table Table Variable Yes Indexes Yes No Statistics Yes No Recompilations
7
First, a Basic Comparison…
Temporary Table Table Variable Full Minimal T-Log Footprint No Yes Table Parameters Yes No Parallelism
8
Image courtesy of Stuart Miles / FreeDigitalPhotos.net
9
Bottom Line If the batch is executed only once in a while
Use a temporary table with OPTION (RECOMPILE)
10
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
11
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
12
Bottom Line If performance with a temporary table is not acceptable
If performance with a table variable is acceptable Use a table variable
13
Bottom Line If performance is not acceptable either way
Try a hybrid solution
14
Bottom Line When using a table-valued parameter
Consider using trace flag 2453
15
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.