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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:17:59+00:00 2026-05-26T06:17:59+00:00

I have sometimes a problem when running a script. I have the probelm when

  • 0

I have sometimes a problem when running a script. I have the probelm when using an application (that I didn’t write and therefore cannot debug) that launches the scripts. This app isn’t returning the full error from SQL Server, but just the error description, so I don’t know exactly where th error comes.

I have the error only using this tool (it is a tool that sends the queries directly to SQL Server, using a DAC component), if I run the query manuallyin management studio I don’t have the error. (This error moreover occurs only on a particular database).

My query is something like:

SELECT * INTO #TEMP_TABLE
  FROM ANOTHER_TABLE 
GO

--some other commands here
GO

INSERT INTO SOME_OTHER_TABLE(FIELD1,FIELD2) 
  SELECT FIELDA, FIELDB
  FROM #TEMP_TABLE  

GO

DROP TABLE #TEMP_TABLE
GO

The error I get is #TEMP_TABLE is not a valid object

So somehow i suspect that the DROP statement is executed before the INSERT statement.

But AFAIK when a GO is there the next statement is not executed until the previous has been completed.

Now I suspoect that this is not true with temp tables… Or do you have another ideas?

  • 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-05-26T06:17:59+00:00Added an answer on May 26, 2026 at 6:17 am

    Your problem is most likely caused by either an end of session prior to the DROP TABLE causing SQL Server to automatically drop the table or the DROP TABLE is being executed in a different session than the other code (that created and used the temporary table) causing the table not to be visible.

    I am assuming that stored procedures are not involved here, because it looks like you are just executing batches, since local temporary tables are also dropped when a stored proc is exited.

    There is a good description of local temporary table behavior in this article on Temporary Tables in SQL Server:

    You get housekeeping with Local Temporary tables; they are
    automatically dropped when they go out of scope, unless explicitly
    dropped by using DROP TABLE. Their scope is more generous than a table
    Variable so you don’t have problems referencing them within batches or
    in dynamic SQL. Local temporary tables are dropped automatically at
    the end of the current session or procedure. Dropping it at the end of
    the procedure that created it can cause head-scratching: a local
    temporary table that is created within a stored procedure or session
    is dropped when it is finished so it cannot be referenced by the
    process that called the stored procedure that created the table. It
    can, however, be referenced by any nested stored procedures executed
    by the stored procedure that created the table. If the nested
    procedure references a temporary table and two temporary tables with
    the same name exist at that time, which table is the query is resolved
    against?

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

Sidebar

Related Questions

I have a BASH/shell script, running on Linux, but it sometimes has a problem
I sometimes have difficulties with other people who wish to solve a problem when
I have a very weird problem: sometimes when I call nHibernate update to an
Where I am: Linux command line The problem I have now: Sometimes I couldn't
In my database application I sometimes have to deal with null strings in the
In our application we sometimes have to make minor GUI modifications for different customers:
I have a quite simple perl script, that in one function does the following:
I have the following code running, but I sometimes get some sort of concurrency
I have a simple script that should cause one of three divs to be
I have a ruby script that performs a lot of memory intensive work. The

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.