Solved

temp table in sql

Posted on 2014-10-15
5
219 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks guys. You are the best.
0
 

Author Comment

by:VBdotnet2005
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now