Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the use cases for temporary tables in SQL database systems?

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.

like image 675
sqlchild Avatar asked Feb 25 '23 03:02

sqlchild


2 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.

like image 81
Robert Harvey Avatar answered Apr 28 '23 10:04

Robert Harvey


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

like image 41
Lynn Langit Avatar answered Apr 28 '23 11:04

Lynn Langit