Alex Gordon
Alex Gordon

Reputation: 60871

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;

Upvotes: 10

Views: 2278

Answers (4)

onedaywhen
onedaywhen

Reputation: 57083

Support for temporary tables exists to allow procedural paradigms in a set-based 4GL, either because the coder has not switched their 3GL mindset to the new paradigm or to work around a performance or syntax issue (perceived or otherwise).

Upvotes: 1

faxi05
faxi05

Reputation: 325

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.

Upvotes: 2

mr.b
mr.b

Reputation: 4992

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.

Upvotes: 3

Marc B
Marc B

Reputation: 360862

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.

Upvotes: 12

Related Questions