Welcome to Microsoft T-SQL Q&A Forum!
Obviously this is a table variable , which uses a variable for storing rows of data , similar to the function of a temporary table .
Why does the stored procedure use table variables here ? This is because using table variables in stored procedures reduces recompilation compared to using temporary tables.
Unlike our common #table , the structure of table variables cannot be changed after declaration , and non-clustered indexes cannot be created for table variables . However , starting with SQL Server 2014 , memory-optimized table variables can be used to introduce new in-memory OLTP , allowing non-clustered indexes to be added as part of table variable declarations . I believe you will encounter this part later .
As an aside , if you want to save the result of your own stored procedure to a table variable , you can do this:
create proc mytest
@id int
as
select 1 as id, ' abc ' as name union all
select @id as id, ' bcd ' as name
declare @table table (id int ,name varchar ( 50 ))
insert into @table exec mytest 2
select *
from @table
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.