T-SQL Tutorial

Table - TSQL Tutorial


On Transact SQL language the table variable is a special data type that can be used to store a result set for processing at a later time. Table variables are automatically will be emptied at the end of the function or stored procedure in which they are defined.

Table syntax:

table

Table example:

USE model;
GO
DECLARE @TableVar table(id int NOT NULL, OldValue char(2), NewValue char(2));
UPDATE my_table SET b='c'
OUTPUT INSERTED.a, DELETED.b, INSERTED.b
INTO @TableVar;
SELECT id, OldValue, NewValue FROM @TableVar;
GO

idOldValueNewValue
1ac
2bc