Is there any way of determining whether or not a specific temp table has been created in a session without referencing the tempdb database that it was created on? Users are allocated to a specific tempdb when they log in, so I don’t know which tempdb they’ll be using.
I don’t need to specify a tempdb to select data out of the temp table, so surely I can see if the table exists?
It seems to me that you shouldn’t be using temporary tables here… these seem more like regular tables (perhaps with a user identifier). What is the scenario here?
Note that using temporary tables in this way can play havoc with the optimiser/query cache – it will have to do lots of recompiles, as the meaning of #FOO changes pretty-much per call.