Dropping a temporary table

Category : Tips User Rating : 4 Stars      Views : 2.5 Stars
One Click Feedback
Please help us to improve the site by rating the quality of this article by clicking a button below.
A temporary table will get automatically dropped at the end of the session that created it. Often this means that you won’t need to worry about dropping temporary tables, however there are occasions where you might want to explicitly drop the table. There are several ways of doing this but I usually use the following code :
IF OBJECT_ID ('tempdb..#MyTempTable') IS NOT NULL
  DROP TABLE #MyTempTable
Link back to this article : https://www.sqlmatters.com/Articles/Dropping a temporary table.aspx

Keywords

TSQL,temp,table


Comments
Post by VillageSmithy on Thu 12 Sep 2024 00:37. Report Inappropriate Post

SQL SERVER versions since 2016 can use the shorter incantation of:
DROP TABLE IF EXISTS #MyTempTable;

Post a comment   No login required !

Name : Email : Website :
Will be displayed alongside your comment
Not displayed Optional, but displayed if entered