Ideally, for best SQL Server performance, you should avoid using temp tables in the first place. Instead, consider using one of these “lower overhead” options instead of using a “higher overhead” temp table.
-
Rewrite your code so that the action you need completed can be done using a standard query or stored procedure.
-
Use the SQL Server 2000 or 2005 “table” datatype.
-
Consider using a correlated sub-query.
-
Use a permanent table instead.
-
Use a UNION statement to mimic a temp table.