TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL CREATE TEMPORARY TABLE Statement

Overview

In this tutorial, we will learn MySQL CREATE TEMPORARY TABLE statement. We can use the CREATE TEMPORARY TABLE statement to create temporary table.

Syntax

CREATE TEMPORARY TABLE <table_name>

<SELECT query>

To create temporary tables, we must have the CREATE TEMPORARY TABLES privilege.

A TEMPORARY table is visible only to the current session, and is dropped automatically when the session is closed. This means that two different sessions can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. The statement creates a table that is kept until the client disconnects.

Example

Let’s create a temporary table using the Country table from the world MySQL database.

mysql> CREATE TEMPORARY TABLE TEMP_US_Countries
              -> SELECT Name, Population
              -> FROM Country
              -> WHERE Continent = ‘North America’;

Query OK, 37 rows affected (0.06 sec)
Records: 37 Duplicates: 0 Warnings: 0

mysql> SELECT COUNT(*) FROM
-> TEMP_US_Countries;
+———-+
| COUNT(*) |
+———-+
| 37 |
+———-+

MySQL CREATE TEMPORARY TABLE

A temporary table is only visible to the client that created it. A temporary table of the same name as an existing permanent table causes the temporary table to override the existing table until the connection or the temporary table is dropped.

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ MySQL Replicate Table using Existing Table› MySQL DROP TABLE Statement

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com