There Is No Difference Between Table Variables, Temporary Tables and Common Table Expressions

I actually saw the above statement posted online. The person making the claim further stated that choosing between these three constructs was "personal preference" and didn't change at all the way SQL Server would choose to deal with them in a query. Let's immediately say, right up front, the title is wrong. Yes, there are very distinct differences between these three constructs. Yes, SQL Server will absolutely deal with these three constructs in different ways. No, picking which one is correct in a given situation is not about personal preference, but rather about the differences in behavior between the three. To illustrate just a few of the differences between these three constructs, I'll use variations of this query: [crayon-5a6d6be4afc7c373837931/] The execution plan for this query looks like this: The number of reads is 1,269 and the duration…
Read More