From the course: Hands-On Advanced SQL Server: Strategies and Techniques

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Table variables

Table variables

- [Instructor] In the last video, you worked with temporary tables, and saw that it was a great way to store and reuse data during a session. Now, in this video, you're going to cover something called table variables, which are kind of like the lighter, more private version of temp tables. So you're going to take a look at what table variables are, and how they differ from temp tables. You're going to learn how to declare and use them and what they're great for, and also, when to avoid them altogether. All right, let's dive in. A table variable lets you store rows of data in memory, just like a temp table, but with simpler syntax and a tighter scope. So here are a couple ways that they differ. For one, table variables are declared with the key word, declare, and not create table. Also, they only live within the current batch or stored procedure. And thirdly, they can't be altered or indexed like a temp table can. Okay, so in front of us here is how you would actually declare a table…

Contents