Home All Groups Group Topic Archive Search About

temp table vs normal table

Author
28 Jul 2005 7:54 PM
Dave
Are the any benefits to using a temp table vs a normal table?

Wouldn't it be better to create a normal table to minimize the load
on tempdb?

Author
28 Jul 2005 8:00 PM
Aaron Bertrand [SQL Server MVP]
> Are the any benefits to using a temp table vs a normal table?

Yes, temp tables are for interim processing, normal tables are for permanent
storage.

One thing you get with temp tables is session independence.  E.g. two users
can create a table called "#foo" at the same time.  Not so with "normal"
tables.

Another is that they are automatically destroyed if you forget to.

> Wouldn't it be better to create a normal table to minimize the load
> on tempdb?

That depends, is tempdb otherwise overloaded?
Author
28 Jul 2005 8:06 PM
Dave
I guess if i had sufficent space allocated for tempdb it wouldn't be a
hit.

I was just wondering if there was a performance benifit for using temp
tables.  It sounds like there are none.
Author
29 Jul 2005 1:48 AM
Brian Selzer
Local temporary tables are visible only to the connection from which they
were created.  There is no lock contention for the table, nor any deadlocks
due to lock escalation.  In addition, tempdb uses the simple recovery model,
which means that only enough information is retained in the transaction log
to rollback any open transactions.  Once a transaction has been committed,
its log space is freed up for use by another transaction.  Production
databases should almost always use the full recovery model, which retains
log entries until the next log backup.  Using a normal table instead of a
temporary table can cause the log disk to fill up.

If you're concerned about the load on tempdb, put it on its own disk
subsystem, or add memory.  Temporary tables and table variables are created
and operated on within memory if it is available.

Show quote
"Dave" <daveg***@gmail.com> wrote in message
news:1122580481.265439.23150@g14g2000cwa.googlegroups.com...
> Are the any benefits to using a temp table vs a normal table?
>
> Wouldn't it be better to create a normal table to minimize the load
> on tempdb?
>
Author
29 Jul 2005 2:40 PM
Dave
Transaction logging seems live a valid argument in favor of temp
tables!   One thing to note incase anyone else is reading this....
derived tables (from my limited experience) have the same issues as
table variables when dealing with very large datasets.

AddThis Social Bookmark Button