Marlon Ribunal compares two techniques:
For this post, I needed to do some research because there is more to
#temptables than simply creating one and using it. As I started digging into the topic, I realized there are a lot of discussions around#temptables and@tablevariables, especially around when one might be a better choice over the other.One of the common arguments is that
#temptables go to disk while@tablevariables stay in memory. Another argument is that this is a myth. That got me curious about what the actual differences are and when they really matter. Discussions like this almost always starts with where the data is stored (disk vs memory).
Yeah, the “table variables are just in memory” is a myth, at least for normal table variables. Memory-valued user-defined table types do change things, as they don’t use tempdb. But they come with their own set of handcuffs.