We have seen a lot of differences between the temporary variable and the temporary table. Here is a nice difference in the Transaction perspective.
A temporary table is transaction dependent and it abides by the database transaction whereas a temporary variable is not transaction bound.
Sample Query
Temporary table
drop table #temp
create table #temp (id int, val varchar(100))
begin tran ins
insert into #temp values (1,'Venkat')
rollback tran ins
select * from #tempWe are not getting any records indicating the temporary table will bound to the transaction strategies.
Temporary variable
declare @tempval table(id int, val varchar(100))
begin tran ins
insert into @tempval values (1,'Venkat')
rollback tran ins
select * from @tempvalEven we have provided rollback transactions. Records are available in the table variable.



Ankit RanaPosted Aug 15, 2018, 2:20 AM EDT
HI, As you told that temp variable always stored in tempdb, I think you need to reconsider this because the temp variable and temp table are in data memory cache if the recordset is small in size. please see this article: https://www.developerfusion.com/article/84397/table-variables-v-temporary-tables-in-sql-server/
Vivek TripathiPosted Jun 6, 2015, 8:35 AM EDT
Nice
Gowtham KTOP 100Posted Jun 6, 2015, 4:07 AM EDT
Nice one
Pankaj Kumar ChoudharyTOP 100Posted Jun 6, 2015, 12:47 AM EDT
Thanks @Santhakumar Sir..........
Santhakumar MunuswamyPosted Jun 5, 2015, 10:17 PM EDT
Thanks for nice article
Rahul PrajapatPosted Jun 5, 2015, 7:32 AM EDT
Nice article panka sir
Atul GuptaPosted Jun 5, 2015, 4:04 AM EDT
Well explained !
NitinPosted Jun 5, 2015, 2:16 AM EDT
nice
Ayush JaiswalPosted Jun 5, 2015, 1:03 AM EDT
Good info