I created a temp table which resides in the temp table folder. The problem is the name is unacceptably long which make it almost impossible to efficiently work on querying some field from it. Is it any way to have a shorter name like db.#SPR1 instead of the long one as below?


  • 2
    I added the "sql-server" tag to your question; please consider properly tagging your question next time, it helps us answer it. Also you may want to include the details and code that you use to create your temporary table. – mustaccio Feb 23 '17 at 19:25

This appears to be Sql Server.

When you created the temporary table, you gave it a meaningful name:

Create Table #Sales (id int, sales decimal(11,2))

Perhaps you created the temporary table using SELECT INTO #Sales FROM...

That is the name you use to reference the table (#Sales).

Due to the fact that other users in the instance can also create a local temporary table with the exact same name, Sql Server has to use an internal 'generated' name to differentiate between YOUR #Sales and another persons #Sales.

You can observe this by creating a temporary table in one session called #Sales with some columns. Under SSMS object explorer, you can see that entry under TEMPDB temporary tables. Now, go to a brand new query window and create the same table. Refresh the TEMPDB temporary tables node and you'll see the newly added temp table. But they are completely independent from each other.

Don't worry about the long weird table name under TempDB – just use the name you gave it at creation time.

And speaking of temporary tables, I'd recommend reading the information in Temporary Tables: Local vs. Global so you'll have a better understanding of how temporary tables work and how long they exist.

Additional information can be found on the Internet by searching for

Difference between local and global temporary table in sql server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.