From the course: Developing Microsoft SQL Server 2016 Databases
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Use table variables - SQL Server Tutorial
From the course: Developing Microsoft SQL Server 2016 Databases
Use table variables
- [Instructor] Temporary tables are a good way to store non-persistent tabular data during a single user session, but sometimes even they exist far longer than required. When you only need a table for a very brief moment then consider using a table variable instead. Table variables get created, used and destroyed all in a single batch operation. It's not possible to use them across multiple calls to the database. Let me show you what this looks like. First, we're going to create a new database called TableVariables that we'll use then we'll come down to this DECLARE statement. I'm going to create a table to store author information as a table variable. This will look a little bit different than the standard CREATE table statement. Instead of creating an object, we are declaring a variable. Just like when creating a temporary table though, we'll add a special symbol to the beginning of a name to denote that this will be a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.