Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 difference between selecting into and temp tables

Author  Topic 

smithani
Starting Member

42 Posts

Posted - 2007-08-27 : 22:12:16
Hello Tsql experts,
Can you please explain to me what the differnce is between selecting into a table and creating a new tabel and inerting in to it like so:

First way:
select names
into #ancestors
from names

and

second way

create table #names(
name varchar(10)
)

insert into #names (name) values(name)
select names from names

is it just personal choice or performance in one method is better than the other.Can you please explain.
Thanks

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-27 : 22:26:40
Depends on rows involved, someone said that second way has better performance with lager amount of data.
Go to Top of Page

Koji Matsumura
Posting Yak Master

141 Posts

Posted - 2007-08-27 : 22:43:20
At least you have more control using the second method such as NULL or NOT NULL.
It maybe required to insert addtional records in following statements.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-28 : 02:29:52
Also if you use first method temp table wont have any indices that source table have. So it is always better to go for method 2

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -