Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Can you name some of the dml commands in sql?

961


How to perform backup for certificates in sql server? : sql server security

1024


What is bit data type? What's the information that can be stored inside a bit column?

874


Define outer join in sql server joins?

890


When cursors are useful?

1036


What is primary key, unique key, and foreign key?

915


Explain database normalization?

1148


What is a fan-out query in SQL Azure?

121


What is application role in sql server database security? : sql server security

993


How to generate create procedure script on an existing stored procedure?

936


application server is slow what may be the problem

2165


Explain how would you store your query in an SSRS report or a Database server?

114


What are the 3 types of schema?

1041


How would we use distinct statement? What is its use?

1022


How do I edit a stored procedure in sql server?

881