BUG: Errors 2714 and 267 on INSERT INTO Global Temp Table

Last reviewed: April 16, 1997
Article ID: Q166200
The information in this article applies to:
  • Microsoft SQL Server, version 6.5
BUG #: 16717

SYMPTOMS

An INSERT INTO a global temp table from a stored procedure may result in the following errors during the second and third executions:

   At the second execution:

      Msg 2714, Level 16, State 1
      There is already an object named '%.*s' in the database.

   At the third execution:

      Msg 267, Level 16, State 1
      Object '%.*s' cannot be found.

The following script demonstrates the problem:

   DROP PROCEDURE sp_test
   GO

   CREATE PROCEDURE sp_test
   AS
   EXEC ("IF EXISTS (SELECT * FROM tempdb..sysobjects
      WHERE name = '##testTable' AND type = 'u')
      DROP TABLE ##testTable")
   CREATE TABLE ##testTable (col INT)
   INSERT INTO ##testTable SELECT 1
   cleanup:
   EXEC ("IF EXISTS (SELECT * FROM tempdb..sysobjects
      WHERE name = '##testTable' AND type = 'u') DROP TABLE ##testTable")
   GO

   EXEC sp_test /* First execution */

      This command did not return data, and it did not return any rows.

   EXEC sp_test /* Second execution */

      Msg 2714, Level 16, State 1
      There is already an object named '##testTable' in the database.

   EXEC sp_test /* Third execution */

      Msg 267, Level 16, State 1
      Object '' cannot be found.

WORKAROUND

To work around this problem, do either of the following:

  • Create the stored procedure with the RECOMPILE option.

    -or-

  • Use the EXECUTE command with the INSERT INTO statement.

The following script demonstrates both of the above workarounds:

   CREATE PROCEDURE sp_test WITH RECOMPILE
   AS
   EXEC ("IF EXISTS (SELECT * FROM tempdb..sysobjects
      WHERE name = '##testTable' AND type = 'u')
      DROP TABLE ##testTable")
   CREATE TABLE ##testTable (col INT)
   EXEC ('INSERT INTO ##testTable SELECT 1')
   cleanup:
   EXEC ("IF EXISTS (SELECT * FROM tempdb..sysobjects
      WHERE name = '##testTable' AND type = 'u') DROP TABLE ##testTable")
   GO

STATUS

Microsoft has confirmed this to be a problem in Microsoft SQL Server version 6.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Keywords : kbbug6.50 kbusage SSrvStProc
Version : 6.5
Platform : WINDOWS
Issue type : kbbug
Resolution Type : kbpending


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.