Reply to Re: Temp Table vs. Union: Which Has Better Performance?

Your name:

Reply:


Posted by Erland Sommarskog on 08/13/07 22:01

imani_technology_spam@yahoo.com (imani_technology_spam@yahoo.com) writes:
> Right now, a client of mine has a T-SQL statement that does the
> following:
>
> 1) Create a temp table.
> 2) Populate temp table with data from one table using an INSERT
> statement.
> 3) Populate temp table with data from another table using an INSERT
> statement.
> 4) SELECT from temp table.
>
> Would it be more efficient to simply SELECT from table1 then UNION
> table 2? The simply wants to see the result set and does not need to
> re-SELECT from the temp table.

Probably, provided that you use UNION ALL. By default UNION implies DISTINCT
which could cause a extra sorting step that could be equally expensive
as the temp table.

But there are always a lot of "it depends" when it comes to performance,
so if there are some deviations from the scenario as you described it,
the real answer may be different.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация