Local Variable Tables are not affected by a transaction

While it might not be immediately obvious, tables declared as local variables are not affected by transactions.  You can create them in transactions and they will still exist outside of the transaction.  The same is true for inserting data:

set nocount on

declare @table1 table(value int)

begin transaction

declare @table2 table (value int)
insert into @table1 values (1)
insert into @table2 values (2)

rollback transaction

select * from @table1
select * from @table2

You would expect at least the data inserted would not be in there right?  Well it is.

This returns:

value      
-----------
          1

value      
-----------
          2

What this really makes these tables useful is when dealing with error messages and such.  You can put errant values in these tables and then rollback, the data is still there.  On the other hand, it can tend to make it a problem if you try to use these tables exactly like local temporary tables (named ##<tablename>.)