• TestingDocs
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

MySQL /

How to secure your SQL Database: Tips and Tricks

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

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

Recent Posts

  • How to secure your SQL Database: Tips and Tricks
  • Shaping the Future of Development: Exploring Key Trends in Software Engineering
  • Improving Java Performance with Multithreading
  • Difference between PHP and JavaScript?
  • Bing Conversation Styles
  • ChatGPT Introduction
  • Open Source AI Frameworks
  • Artificial Intelligence Tools
  • Top AI Music Applications
  • Top AI Website Design Tools

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com