Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Difference between SELECT INTO & SELECT INTO#

Posted on 2002-03-19
3
Medium Priority
?
219 Views
Last Modified: 2006-11-17
Hi,

I am taking over an application using SQL Server but I am not that fluent with it...

There is the SQL command:
Select TUSERS.* into #TNEWTABLE from TUSERS where uid=1

but what is the difference with
Select TUSERS.* into TNEWTABLE from TUSERS where uid=1

Thanks for your help,
Christophe
0
Comment
Question by:FraggleRock
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 6879620
The first one create a temporary table (in tempdb database), the second one a local table (in your current database). The first one will be dropped when you connection ends, the second one remains...

CHeers
0
 
LVL 2

Expert Comment

by:Carlovski
ID: 6879624
The syntax #tablename refers to a temporary table.
So the first statement creates a table which will only last for the lifetime of the connection, whereas the second will create a permanent table.
You may also see ##tablename, which is a global temporrary table, where all users can access the table, but will be deallocated when the last user to access it disconnects.

Regards,
Carl
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 6879651
Brilliant!
Thanks very much.

Christophe
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

972 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