5

what are the main purposes for which temporary tables are used? I want to know the practical and commercial uses of temporary tables in actual softwares working in small and large scale companies.

2
  • For what database? Some don't have such functionality, others can be very different from one another.
    – OMG Ponies
    Commented Feb 12, 2011 at 5:49
  • 5
    a temporary table doesn't have a 'commercial' use. It's a temp table: a table that holds things temporarily! Hopefuly this is a temp question. I'm out of close votes. Commented Feb 12, 2011 at 5:50

3 Answers 3

6

In my experience, temporary tables are often used to store intermediate calculations in a complex series of CREATE or UPDATE queries that produce some sort of analysis result. An example might be the creation of summary tables for an OLAP database.

Temporary tables are also sometimes used to increase performance, in certain situations.

3

I tend to prefer using CTEs (common table expressions) to temporary tables. There is a good discussion in answer to a similar question.

2

In general, Temporary tables are a way to store datasets (generally the result of a complex query) that need to be used further. Many times you can achieve this using subquery. But subquery drags performance. Temp tables help in improving performance by narrowing down the dataset.

Suppose you have a query that needs to join 7–8 tables. Then it's advisable to join the tables having the most minor rows and store their output in the temp table and then join this temp table to other more extensive tables.

It's a good idea to break your bigger joins into smaller ones. In one of the dev projects where I faced these scenarios, the temp table came to rescue me.

As opposed to your assumption Its not used as a draft for a table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.