Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql server 2008, are temp tables unique

In my server code, I create a temp (named #temp) table, insert some data and then delete the temp table. If more than 1 users were to run this section of the code (creating of the temp table) concurrently, would sql server 2008 create a temp table per user or does it create 1 'global' temp table? If its one table, I assume I would run into trouble when the same table is created more than once?

like image 965
Eminem Avatar asked Jul 04 '12 07:07

Eminem


1 Answers

From MSDN:

You can create local and global temporary tables. Local temporary tables are visible only in the current session, and global temporary tables are visible to all sessions
...
If a local temporary table is created in a stored procedure or application that can be executed at the same time by several users, the Database Engine must be able to distinguish the tables created by the different users. The Database Engine does this by internally appending a numeric suffix to each local temporary table name. The full name of a temporary table as stored in the sysobjects table in tempdb is made up of the table name specified in the CREATE TABLE statement and the system-generated numeric suffix. To allow for the suffix, table_name specified for a local temporary name cannot exceed 116 characters.

like image 187
MartW Avatar answered Oct 05 '22 10:10

MartW