Solved

temp table in sql

Posted on 2014-10-15
5
225 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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