DF098: A temporary table has been created but not dropped.

The topic describes the DF098 T-SQL code analysis rule.

Category

BEST PRACTICE

Message

A temporary table has been created but not dropped.

Description

To save resources, it is recommended to promptly drop temporary tables that are no longer needed.

Additional information

Failing to drop temporary tables that are no longer needed can lead to increased resource usage, such as memory and disk space, which can affect overall system performance. Additionally, holding onto unnecessary temporary tables can potentially lead to contention issues and degrade database performance over time. Therefore, it’s advisable to regularly review and drop temporary tables as soon as they are no longer required to optimize resource utilization and maintain efficient database operations.

Noncompliant code example

CREATE TABLE #temp (Id INT NOT NULL);
INSERT INTO #temp(Id) VALUES(12)
SELECT * FROM #temp
GO

Compliant solution

CREATE TABLE #temp (Id INT NOT NULL);
INSERT INTO #temp(Id) VALUES(12)
SELECT * FROM #temp
DROP TABLE IF EXISTS #temp
GO