DF036: Consider using a table variable instead of a temporary table.
Last modified: May 28, 2025
The topic describes the DF036 T-SQL code analysis rule.
Category
BEST PRACTICE
Message
Consider using a table variable instead of a temporary table.
Description
It is recommended to use a table variable instead of a temporary table. Table variables are easier to work with, more secure, and cause fewer recompilations.
Additional information
Table variables are easier to work with, as they behave similarly to regular tables and do not require explicit dropping after use. They are also considered more secure, as their scope is limited to the current session, reducing the risk of conflicts or data leakage. Additionally, using table variables can lead to fewer recompilations compared to temporary tables, resulting in better query performance.
Noncompliant code example
CREATE TABLE #ids (id INT NOT NULL);
Compliant solution
DECLARE @ids TABLE (id INT NOT NULL);
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.