Tables which can be declared and functions similar to a varaible are referred as Table Variables.

Table variables were created in memory inturn enable faster database access. Table variables are considered as good alternative for Temporary tables. Since, temporary tables will create tables in TempDB, there is additional resource utilization in accessing TempDB and Creating tables in TempDB.

Terms and Conditions in using variables:

Unlike temporary tables, table variables adhere to its scope. Temporary tables can be created first and we can execute insert statement or dml operations seperately inside the scope. For example, #a is executed first and afterwards we can execute dml operations subsequently since its stored in database we can use it. Where as, table varaibles resides in memory and doesn't have physical structure, the declaration statement and dml statements should be executed simultaneously else if we try to execute declare statement first(executed) and afterward if we try to access that table an error will be thrown indicating table is not available.

Declaring a table variable:

DECLARE tablevariable-name TABLE ( COLUMN1 TYPE, COLUMN2 TYPE, COLUMN3 TYPE, .....)

Example : declare @TableVariable table(id int,name varchar(20))

All the DML Operations are similar to the Table.

insert into @TableVariable values(1,'Microsoft')

select * from @TableVariable

select * from Table inner join @TableVariable on Table.id= @TableVariable.id