?
Solved

temp table in sql

Posted on 2014-10-15
5
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 668 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 664 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 66

Assisted Solution

by:Jim Horn
Jim Horn earned 668 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

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 …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

741 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