Search notes:

SQL Server - table data type

The table data type is used, for example, for table valued functions or for the output clause in DML statement.

Basic demonstration

The following basic example tries to demonstrate the basic usage of the table data type.
As with any other data type, variables that store a table need to be declared.
After such a declaration, the variable can bu used everywhere where an ordinary table can be used. That is, its possible insert or select from these tables.
set nocount on

declare
   @some_data table (
                 id   integer primary key,
                 val  varchar(20) not null
              );
declare
   @ids_b     table (
                 id   integer
              );

insert into @some_data values
   (1, 'foo'),
   (2, 'bar'),
   (3, 'baz');

insert into
   @ids_b
select
   id
from
   @some_data
where
   val like 'b%';

select
   id
from
   @ids_b;
--
-- id
-- -----------
-- 2
-- 3
Github repository about-MSSQL, path: /t-sql/data-types/table/intro.sql

See also

SQL Server: Data types
SQL tables
Assign values to variables in a select statement
The table data type is not found in sys.systypes.
The table variable deferred compilation feature (IQP Features)

Index