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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Temp Table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-02-18 : 23:45:49
Greg writes "Can you tell me which is more efficient when using SQL Server 7?

1)
SELECT field1, field2 INTO #temptable FROM sometable
OR
2)
CREATE TABLE #temptable (field1int, field2 varchar(20))
INSERT INTO #temptable SELECT value1, value2 FROM sometable

I have been told the first is better because it doesn't do any logging. Then I have also been told the second is better because it doesn't have to query the system tables to figure out how to build the temp table first. What do you think?"

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-19 : 10:40:59
How much data are we talking about? How often does this process have to be repeated? Does this process need to be releaed to a production environement? How large did you define tempdb? Do you need to rollback transactions with in the session? Does the table need to be retained?

Like all things, the answer will be: "It depends"

Let us know what you're doing and maybe we can assist.

Brett

8-)


Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-02-19 : 11:11:04
1. will almost certainly be faster.
Should never be used in dynamic sql or on pre v7 systems though.

I prefer to use 2 unless a select into is needed for reduced logging.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -