Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8490425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:06:52+00:00 2026-06-10T22:06:52+00:00

When using temp tables in SQL Server stored procs, is the preferred practice to;

  • 0

When using temp tables in SQL Server stored procs, is the preferred practice to;

1) Create the temp table, populate it, use it then drop it

CREATE TABLE #MyTable ( ... )

-- Do stuff

DROP TABLE #MyTable

2) Check if it exists, drop it if it does, then create and use it

IF object_id('tempdb..#MyTable') IS NOT NULL
DROP TABLE #MyTable

CREATE TABLE #MyTable ( ... )

3) Create it and let SQL Server clean it up when it goes out of scope

CREATE TABLE #MyTable ( ... )

-- Do Stuff

I read in this answer and its associated comments, that this can be useful in situations where the temp table is reused that SQL Server will truncate the table but keep the structure to save time.

My stored proc is likely to be called pretty frequently, but it only contains a few columns, so I don’t know how advantageous this really is in my situation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:06:54+00:00Added an answer on June 10, 2026 at 10:06 pm

    You could test and see if one method outperforms another in your scenario. I’ve heard about this reuse benefit but I haven’t performed any extensive tests myself. (My gut instinct is to explicitly drop any #temp objects I’ve created.)

    In a single stored procedure you should never have to check if the table exists – unless it is also possible that the procedure is being called from another procedure that might have created a table with the same name. This is why it is good practice to name #temp tables meaningfully instead of using #t, #x, #y etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server 2000, and many of the stored procedures it use temp
Similar to Insert into a temp table from a stored procedure on Sql Server
Using SQL Server 2008, I have two stored procedures - create procedure [dbo].[SH_Export_data] (@unit
I am using SSIS to move excel data to a temp sql server table
I want to do the following using SQL Server 2005. Create a stored procedure
Scenario I have a stored procedure written in T-Sql using SQL Server 2005. SEL_ValuesByAssetName
I'm using SQL Server 2K8 and have a table used solely to generate ids
I'm using SQL Server 2005. I have a series of product and pricing tables
In a stored procedure (using SQL Server 2008 R2 SP2) is it possible to
I am using SQL Server 2005. I have created a table with the columns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.