title: Is it a best practice to drop the temp table after using it, in addition to before creating the temp table?
body: <p>I have a stored proc that creates a temp table. It is only needed for the scope of this stored proc, and no where else.</p>
  
  <p>When I use temp tables list this, I always check to see if the temp table exists, and drop it if it does, before creating it in the stored proc. I.e.:</p>
  
  <pre><code>IF OBJECT_ID('tempdb..#task_role_order') IS NOT NULL    
          DROP TABLE #task_role_order        
  CREATE TABLE #task_role_order(...)
  </code></pre>
  
  <p>Most of the time, is it a best practice to drop the temp table when done with it, in addition to before creating the temp table? </p>
  
  <p>If more context is needed, I have a .NET Web API back end that calls stored procs in the database. I believe that SQL server drops the temp table when the SQL Server session ends. But I don't know if .NET opens a new SQL Server session each time it queries the database, or only once per application lifecycle, etc.</p>
  
  <p>I've read this <a href="https://stackoverflow.com/questions/12302648/what-is-the-preferred-method-of-creating-using-and-dropping-temp-tables-in-sql">similar question</a>, but thought that it was slightly different.</p>