Microsoft SQL Server Drop Keyword Drop temporary tables

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

In SQL server we have 2 types of temporary tables:

  1. ##GlobalTempTable is a type of temporary table that is sheered between all user's sessions.
  2. #LocalTempTable temp tab - it is a type of temporary table that only exists in current scope (only in actual process - you can get id of your current process by SELECT @@SPID)

Droping process of temporary tables is the same as for normal table:

DROP TABLE [ database_name . [ schema_name ] . | schema_name . ] table_name   

BEFORE SQL Server 2016:

IF(OBJECT_ID('tempdb..#TempTable') is not null)
    DROP TABLE #TempTable;

SQL Server 2016:

DROP TABLE IF EXISTS #TempTable


Got any Microsoft SQL Server Question?