Home > Ask the SQL Server Experts > Archive: Integration Services Questions & Answers > Create private temp tables for many users to execute same procedure
Ask The SQL Server Expert: Questions & Answers
EMAIL THIS

Create private temp tables for many users to execute same procedure

Joe Toscano EXPERT RESPONSE FROM: Joe Toscano

Pose a Question
Other SQL Server Categories
Meet all SQL Server Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 30 May 2006
I have a temporary table in a stored procedure (based on defined columns). If I am executing the procedure and someone else executes that same procedure, it won't allow the other person to execute until I drop the temporary table. This is normal. Is there any way to name the temporary table based on a variable?

For instance, if I am executing the procedure the temp table name will be #xyz_my_id and if someone else executes the same procedure it creates temp table with the name #xyz_his_id. This way both of us can execute the same procedure without waiting for temp table to be dropped.


>
If you create a private temporary table in your stored procedure many people should be able to execute the procedure simultaneously. By private temp table I mean a table with a single # such as #SalesTable. If you look in tempdb you will see the table actually created contains the name #SalesTable with '_______________SOMEUNIQUEID' appended to it.

This naming convention actually allows one to create private temp tables with the same exact names as your neighbors. While we reference them as #SalesTable internally they are stored with the unique identifier value appended to it. If you create a global temporary table these are actual tables created 'as is' in the tempdb database with a double pound ## naming convention such as ##SalesTable.

With global temp tables you may experience locking and blocking. If you absolutely must use global temp tables you can consider creating the table using a guide as the table name (with the –'s removed of course because they aren't allowed in the table name). In fact, I've created unique tables using the newid() function to generate a uniqueidentifier value.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Archive: Integration Services
How to convert DTS packages to SSIS and overwrite data
How to migrate DTS to SSIS and deploy SSIS packages
Query to search text in old DTS packages in SQL Server?
Error importing Excel data to SSIS in SQL Server 2005
Delete .bak files automatically with CLR
DTS package designed to overwrite extract.xls
Displaying a SQL Server database report in Excel
Stored procedure practices in SQL Server
Call triggers in a stored procedure
SQL Server permission to create jobs and schedules in SSIS

SQL Server Stored Procedures
SQL Server Mailbag: CALs, witnesses and unwanted changes
SQL Server Mailbag: Stored procedures, triggers and SSRS reports
Top tips and tricks for SQL Server database development
Top 10 SQL Server development tips of 2008
SQL Server trigger vs. stored procedure to receive data notification
SQL Server errors, failures and other problems fixed from the trenches
SQL Server and data manipulation in T-SQL
How to use SQL Server 2008 hierarchyid data type
SQL Server stored procedures tutorial: Write, tune and get examples
Check SQL Server database and log file size with this stored procedure

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
library  (SearchSQLServer.com)
trigger  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



SQL Solutions - SQL Database Design
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts