Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: what is a temporary table?

What is the purpose of a temporary table like in the following statement? How is it different than a regular table?

CREATE TEMPORARY TABLE tmptable
SELECT A.* FROM batchinfo_2009 AS A, calibration_2009 AS B
WHERE A.reporttime LIKE '%2010%'
AND A.rowid = B.rowid;
like image 704
Alex Gordon Avatar asked May 21 '10 21:05

Alex Gordon


3 Answers

Temp tables are kept only for the duration of your session with the sever. Once the connection's severed for any reason, the table's automatically dropped. They're also only visible to the current user, so multiple users can use the same temporary table name without conflict.

like image 190
Marc B Avatar answered Oct 06 '22 01:10

Marc B


Temporary table ceases to exist when connection is closed. So, its purpose is for instance to hold temporary result set that has to be worked on, before it will be used.

like image 22
mr.b Avatar answered Oct 06 '22 02:10

mr.b


Temporary tables are mostly used to store query results that need further processing, for instance if the result needs to be queried or refined again or is going to be used at different occasions by your application. Usually the data stored in a temporary database contains information from several regular tables (like in your example).

Temporary tables are deleted automatically when the current database session is terminated.

like image 29
faxi05 Avatar answered Oct 06 '22 01:10

faxi05