Home > Database > Mysql Tutorial > What are MySQL temporary tables? How do we create them?

What are MySQL temporary tables? How do we create them?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-09-06 10:57:02
forward
988 people have browsed it

什么是 MySQL 临时表?我们如何创建它们?

As the name suggests, a temporary table is a table where we can save temporary data. The most important thing about temporary tables is that they are deleted when the current client session terminates. It can be created with the help of CREATE statement but we have to use keyword "Temporary" while creating it. To illustrate the creation of 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)
Copy after login

The above query has created the value and inserted it into a temporary table named "SalesSummary" middle.

The above is the detailed content of What are MySQL temporary tables? How do we create them?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template