O'Reilly logo

SQL: Visual QuickStart Guide by Chris Fehily

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Temporary Table with CREATE TEMPORARY TABLE

Every table I’ve created so far has been a permanent table, called a base table, which stores data persistently until you destroy (DROP) the table explicitly. SQL also lets you create temporary tables to use for working storage or intermediate results. Temporary tables commonly are used to:

  • Store the result of a complex, time-consuming query once and use the result repeatedly in subsequent queries, improving performance greatly.

  • Create an image, or snapshot, of a table at a particular moment in time. (You can add a column with the DEFAULT value CURRENT_TIMESTAMP for recording the exact time.)

  • Hold the result of a subquery; see the DBMS Tip in “Creating Outer Joins with OUTER JOIN” in Chapter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required