Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a temporary table

Status
Not open for further replies.

solo1234

Programmer
Jun 25, 2007
39
NL
Dear all,

Is there any difference in speed using a temporary table or a normal table in sql server 2000.

for example;
select * into #temp from any_table

When any table has a lot of records, is it faster to use #temp or the any_table.

Nice regards,
Michelle.
 
2 reads (read any_table and insert into #temp then read #temp)
will be slower than 1 read from any_table

 
In the example you have provided, it will be much faster to use the real table. I don't see any valid reasons for you to contemplate creating a temporary table when all you are doing is making an exact copy of the table and it's data.

[!]
-------------------------------------------------------

Mark,

Join me at the new IT Community of the 21st Century: [!][URL unfurl="true"]http://lessthandot.com[/!][/url]

[/!]
 
I don't see any valid reasons for you to contemplate creating a temporary table when all you are doing is making an exact copy of the table and it's data."

In the shop I work in it can be useful on the production server. I can't create tables there but they are not always linked so I can get to production from test. It wouldn't be a straight copy though so I agree with what you are saying. It would be a subset used further down. I think the OP used that as an example to illustrate the question.
 
Yes, I can see how creating temporary tables are useful. It was in context of the original posters example that it makes no sense to create one.

[!]
-------------------------------------------------------

Mark,

Join me at the new IT Community of the 21st Century: [!][URL unfurl="true"]http://lessthandot.com[/!][/url]

[/!]
 
Thanks for all the usefull information.

Michelle.
 
I wouild also suggest that if you are filtering the data, a derived table can be faster than either a temp table ora table vaiable. But as with all performance questions, the real anaswer depends greatly on your own database design and the actual data and the frequency the data is being accessed. I would try all three and see which works best in your own particular situation.

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top