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.
-
For what database? Some don't have such functionality, others can be very different from one another.– OMG PoniesCommented Feb 12, 2011 at 5:49
-
5a 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.– Mitch WheatCommented Feb 12, 2011 at 5:50
3 Answers
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.
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