This post is in Draft Mode - it will not appear on the site or in search results

Difference between Table Variable, Temp Table, Table Type, and Common Table Expression

-

Intro

There are several different options for storing and passing tabular data:

  1. Table Variables
  2. Temp Tables
  3. User-Defined Table Types
  4. Common Table Expression

Let's look first look at how to use each, and then figure out when/why to do so.

Syntax Overview

Table Variables

Temp Tables

User-Defined Table Type

Common Table Expression

Comparison