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 8164617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:21:29+00:00 2026-06-06T19:21:29+00:00

We have an issue upgrading to SQL Server 2012. I am using the following

  • 0

We have an issue upgrading to SQL Server 2012. I am using the following script to create temporary tables that used to work fine on SQL Server 2008 R2 but now it is generating an error with 2012:

if (OBJECT_ID( 'tempdb..#idstable') > 0)
    truncate table #idstable
else
    create table #idstable (id int not null)

the error thrown is

There is already an object named ‘#idstable’ in the database.

This is obviously not thrown the first time I use the script (in the same transaction).

Any idea? Thank you!

  • 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-06T19:21:30+00:00Added an answer on June 6, 2026 at 7:21 pm

    In SQL Server 2012, #temp tables are created with a negative object_id, so your script won’t work as is. The safest way is:

    IF OBJECT_ID( 'tempdb..#idstable') IS NOT NULL
    

    (I blogged about this here, and knew it would catch someone.)

    Though your script is bound for failure anyway, if it is part of a single batch. The parser will not let you try and create the same #temp table twice.

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

Sidebar

Related Questions

I have a .NET 3.5 website that is uploading files to a SQL Server
I have a little issue with upgrading my sqlite database. For now I'm using
we have an issue with an access database we are upgrading to use SQL
Have a weird issue. I am upgrading from 5.6.2 and following the documented suggested
I have made a script that run various loops and does some SQL inserts.
I am using MAMP 2.0.5 and I have an issue upgrading PEAR MAMP: How
I have an odd issue that started appearing after upgrading EPiServer CMS 6 to
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I have been investigating some performance issues with my database (SQL Server 2008). SQL

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.