Solved

temp table in sql

Posted on 2014-10-15
5
223 Views
Last Modified: 2014-10-15
I want to select from a table and put it in temptable. I created a simple one below. My question is if two users load aspx page
at the same them, let's say, user1 starts first and user2 starts right after, user2 wouldn't  drop #temp_1, right while
user1 running?

DROP TABLE #TEMP_1
SELECT * INTO #TEMP_1
FROM (select itemno, cid, shippdate, etc...) a
0
Comment
Question by:VBdotnet2005
5 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 167 total points
ID: 40382436
each temp table is unique for session. So in your case answer is yes
0
 
LVL 25

Assisted Solution

by:Lee Savidge
Lee Savidge earned 166 total points
ID: 40382442
No you wouldn't have a problem. Tables declared with #temp for example, are only available to that session. If they are named ##temp for example, then they are available globally to all sessions. In your example each user would connect under a different SPID which will prevent any crossover. They would in effect, get their own #temp tables.
0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 167 total points
ID: 40382446
The above answers are correct.

As an aside, T-SQL will throw an error if it attepts to drop a table that doesn't exist, so add this to your code..
IF OBJECT_ID('tempdb..#TEMP_1) IS NOT NULL
   DROP TABLE #TEMP_1
GO

SELECT * INTO #TEMP_1
FROM (select itemno, cid, shippdate, etc...) a

Open in new window

0
 

Author Comment

by:VBdotnet2005
ID: 40382453
Thanks guys. You are the best.
0
 

Author Comment

by:VBdotnet2005
ID: 40382557
IF OBJECT_ID('tempdb..#TEMP_1') IS NOT NULL
   DROP TABLE #TEMP_1
GO

SELECT * INTO #TEMP_1
FROM (select itemno, cid, shippdate, etc...) a
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question