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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Views vs. Temp Tables

Status
Not open for further replies.

jflmeing

Programmer
Jan 10, 2001
30
US
Which is better to use, a view or a temp table? I know temp tables are built in tempdb, but where is the data for a view stored - ins't a view similar to a temp table?

Thank you,
Jennifer
 
Hello,

A view is like a query, it does not store any information. A temp table does store information for a finite period of time (until you drop it or the connection is severed).

As to which is better to use, that depends on your needs.

Carla

Documentation: A Shaft of light into a Coded world
 
Usually it is better to use a view for two reasons:
First, with a view the data is always current whereas with a temp table the data is a "snapshot" of the data taken at a point of time, and it never changes even if the data in the source or parent table changes, and
second, as Carla points out, there is no data stored, which, depending on your situation, could be a huge space savings.

The downside to using views is that the Server has to collect all the data into a result set (basically it has to re-run the query to retrieve all the data) every time you want to use the view, whereas in a temp table the data is already stored and waiting for you.

Even so, usually you want to use views because you usually want the most current data.


Mike Krausnick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top