Monday, July 8, 2013

Table Variable in SQL

 Table Variable

 Temporary table is the Table variable which can do all kinds of operations that we can perform inTemp table. Below is the syntax for using Table variable.

Declare @TempTableVariable TABLE(
UserID int,
UserName varchar(50), 
UserAddress varchar(150))
The below scripts are used to insert and read the records for Tablevariables:
insert into @TempTableVariable values ( 1, 'Anna','Paris');
Now select records from that tablevariable:
select * from @TempTableVariable

When to Use Table Variable Over Temp Table

Tablevariable is always useful for less data. If the result set returns a large number of records, we need to go for temp table.

No comments:

Post a Comment