Mike Arney (4/15/2009)
First, thanks for the comment about object_id('tempdb..#t'): I did not realize that would reliably work. I was afraid if 2 sessions both had a #t, object_id() would have the same problem as something like "select * from tempdb.sys.objects where name like '#t%' ", namely, it would not distinguish between the different #t's in the different sessions. Seems that it does that just fine.
That's because, behind the scenes, the local temp table isn't named simply "#t". It'll be something like...
#t_________________________________________________________________________________________________________12A52C39F0
That's what allows local temp table to be session specific and also prevents mutual interfernce between sessions that all want to use a #t table.
--Jeff Moden
Change is inevitable... Change for the better is not.