When creating temp tables within a stored procedure, is it good practice to drop them as soon as they are no longer required?

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 a derived table.

  • 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.



No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |