
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What are MySQL Temporary Tables? How can we create them?
As the name suggests, Temporary tables are the tables in which we can keep our temporary data. The most important thing about temporary tables is that they will be deleted when the current client session terminates. It can be created with the help of the CREATE statement but we must have to use the keyword ‘Temporary’ while creating it. To illustrate the creation of a temporary table we are using the following example −
Example
mysql> CREATE TEMPORARY TABLE SalesSummary ( -> product_name VARCHAR(50) NOT NULL -> , total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00 -> , avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00 -> , total_units_sold INT UNSIGNED NOT NULL DEFAULT 0 ); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO SalesSummary -> (product_name, total_sales, avg_unit_price, total_units_sold) -> VALUES -> ('cucumber', 100.25, 90, 2); mysql> SELECT * FROM SalesSummary; +--------------+-------------+----------------+------------------+ | product_name | total_sales | avg_unit_price | total_units_sold | +--------------+-------------+----------------+------------------+ | cucumber | 100.25 | 90.00 | 2 | +--------------+-------------+----------------+------------------+ 1 row in set (0.00 sec)
The above queries have created and inserted the values into a temporary table named ‘SalesSummary’.
- Related Articles
- How can we see MySQL temporary tables in the list of tables?
- What are MySQL stored functions and how can we create them?
- How can we create a MySQL temporary table by using PHP script?
- How can I see the description of a MySQL Temporary Tables?
- What are weeds? How can we control them?
- How can we create a MySQL view by using data from multiple tables?
- What happens to MySQL temporary tables if MySQL session is ended?
- How can we access tables through MySQL stored procedures?
- How can we compare data in two MySQL tables?
- How can we create MySQL views?
- Update column data without using temporary tables in MySQL?
- How can we upload data into MySQL tables by using mysqlimport?
- How can I delete MySQL temporary table?
- Fix Error with TYPE=HEAP for temporary tables in MySQL?
- How can we upload data into multiple MySQL tables by using mysqlimport?

Advertisements