Odd "Cannot find a table or object" error

  • I run this code to create a temp table:

    CREATE TABLE #EID ( ID INT, Ename VARCHAR(10) )

    INSERT INTO #EID ( ID, Ename )

    SELECT 1, 'hello'

    SELECT * FROM #EID

    DBCC DBREINDEX( #EID, ' ',90)

    The last line gives me:

    Msg 2501, Level 16, State 45, Line 8

    Cannot find a table or object with the name "#EID". Check the system catalog.

    but clearly this exists. I'm porting code from sql server 2000 to 2005. Is this a stupid error message and the problem is actually somewhere else?

  • Another subtle difference between SQL 2000 and SQL2005. Try this:-

    CREATE TABLE #EID ( ID INT, Ename VARCHAR(10) )

    INSERT INTO #EID ( ID, Ename )

    SELECT 1, 'hello'

    SELECT * FROM #EID

    DBCC DBREINDEX( 'tempdb..#EID', ' ',90)

  • Brilliant - that's it. (I actually tried that without the quotes).

    Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply