What is the difference between temp table and table variable?
Answer Posted / balasubramaiam s( ramco system
Table variables are Transaction neutral. They are variables
and thus aren't bound to a transaction.
Temp tables behave same as normal tables and are bound by
transactions.
BEGIN TRAN
declare @var table (id int, data varchar(20) )
create table #temp (id int, data varchar(20) )
insert into @var
select 1, 'data 1' union all
select 2, 'data 2' union all
select 3, 'data 3'
insert into #temp
select 1, 'data 1' union all
select 2, 'data 2' union all
select 3, 'data 3'
select * from #temp
select * from @var
ROLLBACK
select * from @var
if object_id('tempdb..#temp') is null
select '#temp does not exist outside the transaction'
We see that the table variable still exists and has all
it's data unlike the temporary table that doesn't exists
when the transaction rollbacked.
| Is This Answer Correct ? | 13 Yes | 0 No |
Post New Answer View All Answers
What happens if you insert a duplicate key for the primary key column in ms sql server?
what is spatial nonclustered index
Do you know what is difference between stored procedure and user defined function?
What is subreport?
How would you go about developing a ssrs report?
How can we rewrite sub-queries into simple select statements or with joins?
What is the use of group by clause?
What is the use of commit?
What is the meaning of resultset type_scroll_insensitive?
Explain stored procedure?
Explain about integration services of Microsoft SQL server?
Explain the third normal form(3nf)?
Explain what are the authentication modes in sql server?
What are triggers? How many triggers you can have on a table? How to invoke a trigger on demand?
Is natural join and equi join same?